Learn how to extract nested ZIP archives in C#: https://blog.aspose.com/2022/01/12/extract-nested-zip-archives-in-csharp-net/
Last active
January 12, 2022 15:02
-
-
Save aspose-com-gists/8824e9c135d78f07ef109019d9d9174e to your computer and use it in GitHub Desktop.
Extract or Unzip Nested ZIP Archives in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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