Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active January 12, 2022 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/8824e9c135d78f07ef109019d9d9174e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/8824e9c135d78f07ef109019d9d9174e to your computer and use it in GitHub Desktop.
Extract or Unzip Nested ZIP Archives in C# .NET
// 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);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment