We often come across the scenario where multiple ZIP archives are encapsulated inside another ZIP. In such cases, first, you have to extract the parent ZIP and then the nested archives one by one. To make things easier for you, in this article, we will demonstrate how to extract the nested ZIP archives in C# .NET without writing complex code.
C# .NET API to Extract Nested ZIP Archives
To unzip the nested ZIP archives, we will utilize Aspose.ZIP for .NET. The API is designed to perform archiving operations from within the .NET applications. It allows you to create and manipulate popular archive formats seamlessly. You can either download the API’s DLL or install it using NuGet.
PM> Install-Package Aspose.Zip
Extract Nested ZIP Archives in C#
To demonstrate the extraction of nested ZIP archives, we have created the following ZIP file which contains 3 entries.
We will extract each nested ZIP archive and save its content in a separate folder. The following are the steps to extract nested ZIP archives in C#.
- First, create a FileStream object to load ZIP file.
- Then, load ZIP file using Archive class.
- Iterate through each ArchiveEntry in Archive.Entries collection.
- Filter the ZIP archives in the collection and for each archive perform following steps:
The following code sample shows how to unzip nested ZIP archives in C# .NET.
The following is the screenshot of the extracted ZIP archives.
Get a Free API License
You can get a free temporary license to use Aspose.ZIP for .NET without evaluation limitations.
In this article, you have learned how to extract nested ZIP archives in C#. The step-by-step guide and code sample have demonstrated how to unzip each nested archive into a separate folder. Besides, you can visit documentation to explore other features of Aspose.ZIP for .NET. Also, you can ask your questions via our forum.