How to Create ZIP File in Memory in C#

In this step-by-step tutorial, you will learn how to create ZIP file in memory in C#. You need to execute following simple steps to be able to create ZIP archive in memory.

Steps to Create ZIP File in Memory in C#

  1. Add Aspose.ZIP for .NET NuGet package reference to solution
  2. Add using Aspose.Zip statement in Program.cs code file
  3. Apply license for Aspose.ZIP API using License.SetLicense method
  4. Get single or all Files from Folder located on disk & store their paths in string array
  5. Create object of Archive Class in memory
  6. For each file, create an ArchiveEntry node in ZIP Archive
  7. Save or copy ZIP Archive instance to MemoryStream

The following C# code example can be used in your .NET application to compress all files in a folder on disk to ZIP file format and then store ZIP file in memory stream object.

Code to Create ZIP File in Memory in C#

So, this C# create zip file in memory console application will essentially help you to convert folder to ZIP format and write folder’s entire content in memory in compressed format. Afterwards, you can re-create ZIP file from MemoryStream C# and save to disk. Once the archive is re-created on file system, you can then extract ZIP file using C# code.

 English