There is some sample code in an aspose blog that shows how to extract a zip from a zip file but it throws an error when I try to run in on a zip file I have that contains two other zip files. The zip file opens fine in WinZip pro, but from the sample code it throws the error:
System.IO.InvalidDataException
HResult=0x80131501
Message=Signature of end of central directory does not match. Make sure the source is valid zip archive.
Source=Aspose.Zip
The code from the blog throws an error on the line using (var nestedArchive = new Archive(nestedArchiveStream))
The code in the blog is:
// Open ZIP file in a file stream
using (FileStream zipFile = File.Open(“Archives/nested-archive.zip”, FileMode.Open))
{
// Load ZIP file using Archive class
using (Archive archive = new Archive(zipFile, new ArchiveLoadOptions()))
{
// Access each entry in ZIP archive
foreach(ArchiveEntry entry in archive.Entries)
{
if(entry.Name.ToLower().Contains(".zip"))
{
// Create memory stream for nested archive
MemoryStream nestedArchiveStream = new MemoryStream();
// Copy archive to memory stream
entry.Open().CopyTo(nestedArchiveStream);
// Load the nested archive from memory stream
using (var nestedArchive = new Archive(nestedArchiveStream))
{
// Extract archive to disk.
nestedArchive.ExtractToDirectory("Archives/Extracted/"+entry.Name);
}
}
}
}
}