Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Getting an array of ZippedFile objects?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20211 |

    Is there a way to get an array of ZippedFile objects from a ZipArchive?  I can see how to get AbstractFile[] using ZipArchive.GetFiles(), but I’d like to work with the full ZippedFile object and all of the additional properties.

     

    Thanks,

    -Steve 

    Imported from legacy forums. Posted by Steve (had 1316 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Steve,

     

    Find below a possible implementation of casting the AbstractFile into a ZippedFile.

     

    Example:

    ZipArchive zipArchive = new ZipArchive( new DiskFile( @”” ) );

                ZippedFile[] zippedFiles = new ZippedFile[zipArchive.GetFiles( true, null ).Count()];

                int i = 0;

                foreach( AbstractFile file in (zipArchive.GetFiles(true,null) ))

                {

                    if( file.GetType() == typeof( ZippedFile ) )

                    {

                        zippedFiles[ i ] = file as ZippedFile;

     

                    }

                    ++i;

                }

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 298 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks!

    -Steve 

    Imported from legacy forums. Posted by Steve (had 317 views)

    User (Old forums)
    Member
    Post count: 23064

     Still having problems with casting AbstractFile to a ZippedFile.
     
    I’m getting an exception when I try to do the following:
     
                    try
                    {
                        DiskFile zipFile = new DiskFile(myzipFile);
                        ZipArchive zip = new ZipArchive(zipFile); 
                        archiveDictionary.Clear();
                        foreach (AbstractFile afile in zip.GetFiles(true))
                        {
                            if (afile.GetType() == typeof(ZippedFile))
                            { 
              —–>           ZippedFile zf = new ZippedFile(afile, afile.FullName);
                                archiveDictionary.Add(afile.FullName, zf);
                                Debug.WriteLine(“archiveDictionary added: ” + afile.FullName);
                            } 
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.Message + ” :: ” + e.StackTrace);
                    } 
     
    The exception is being thrown on the line where it is creating the new ZippedFile object.  Here is the exception message and stack:
     
     The zip end header signature could not be found in the zip file.
    Zip file: Final Analysis.doc ::    at Xceed.Zip.ZipHandler.ReadEndHeader(BinaryReader reader, ZipStream stream)
       at Xceed.Zip.ZipHandler.Refresh(FileSystemEventsSession session)
       at Xceed.Zip.ZipHandler.GetZipHandler(FileSystemEventsSession session, AbstractFile zipFile)
       at Xceed.Zip.ZippedFile..ctor(FileSystemEvents events, Object userData, AbstractFile zipFile, String fileName)
       at Xceed.Zip.ZippedFile..ctor(AbstractFile zipFile, String fileName)
       at Test.Extractor.Open(String file) in C:\Documents and Settings\Administrator\Desktop\Development\Test\Extractor.cs:line 935
     
     
    I also eliminated the line where it creates a new ZippedFile object and modified the next line like so:
     
    archiveDictionary.Add(afile.FullName, afile as ZippedFile);
     
    But it threw the same exception at that point.
     
    -Steve 

    Imported from legacy forums. Posted by Steve (had 451 views)

    Xceed Support
    Member
    Post count: 5658

    You should write :

    ZippedFile zf = afile as ZippedFile;

     

    Instead of

    ZippedFile zf = new ZippedFile(afile, afile.FullName);

    Then, you should not have any exception.

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 1383 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.