Create a Flat ZIP Archive in C#

Often, you get a ZIP archive that contains other ZIP archives inside it forming a nested structure of the archives. In such cases, you may want to get a flat structure by extracting all the inner ZIP archives into the outer archive. To perform this operation programmatically, this article shows how to create a flat ZIP archive in C#.

C# .NET API to Create Flat ZIP Archives

To create the flat ZIP archives, we will use Aspose.ZIP for .NET. It is an archiving API that is designed to create and extract popular archive formats including ZIP, TAR, GZip, and 7z. You can either install the API from NuGet or download its DLL from the downloads section.

PM> Install-Package Aspose.Zip

Create a Flat ZIP Archive in C#

To understand the structure of a flat ZIP archive, let’s take an example. The following is a ZIP archive that contains another ZIP archive inside it.

parent.zip
 ├first.txt
 ├inner.zip
 │ ├game.exe
 │ └subitem.bin
 └picture.gif

After transforming this ZIP archive to a flat ZIP, all the entries of the inner ZIP will be extracted into the parent ZIP. Finally, we’ll get the following structure of the parent ZIP.

flatten.zip
 ├first.txt
 ├picture.gif
 ├game.exe
 └subitem.bin

Let’s see how to perform this transformation programmatically. The following are the steps to create a flat ZIP archive in C#.

The following code sample shows how to create a flat ZIP archive in C#.

Get a Free API License

You can get a free temporary license to use Aspose.ZIP for .NET without evaluation limitations.

Conclusion

In this article, you have learned how to create a flat ZIP archive programmatically in C#. Particularly, we have demonstrated how to make a flat ZIP by extracting the inner ZIP archives into the parent ZIP. Apart from that, you can visit the documentation to read more about Aspose.ZIP for .NET. Also, you can share your queries with us via our forum.

See Also