If you are looking for a way of extracting ZIP archives programmatically, this article is going to give you the easiest solution. It will demonstrate how to extract ZIP archives using C# in a few simple steps.

Extract ZIP Files in C#

In the previous article, you have learned different ways of creating ZIP files and folders using Aspose.ZIP for .NET. This article will cover how to extract ZIP files and unzip password-protected or AES encrypted ZIP archives in C#.

Extract ZIP Archives in C# - API Installation

Before we start, make sure you have downloaded and referenced Aspose.ZIP for .NET or installed its package using NuGet Package Manager in your project.

PM> NuGet\Install-Package Aspose.Zip

How to Extract ZIP Files in C#

The process of extracting ZIP files could be achieved in two way:

  • Extract each file in ZIP separately
  • Extract files into a specified folder

In the first method, you can explicitly access and extract each file in the ZIP archive. Furthermore, you can print the progress of the extraction process. Whereas, the second method simply extracts the files into the specified folder.

C# Extract Each File in ZIP

The following are the steps to access and extract a ZIP file in C# and print the extraction progress:

The following code sample shows how to extract files in a ZIP archive in C#.

Unzip ZIP Files into a Folder in C#

The following steps are used to unzip ZIP files into a specific folder in C#.

The following C# code sample unzips ZIP files into a folder.

C# Unzip Password-Protected ZIP Files

You can also unzip a password-protected ZIP archive using Aspose.ZIP for .NET. For this, you only need to specify the password using the ArchiveLoadOptions class that will be passed as a second parameter to the Archive’s constructor.

The following is the sample code to unzip a password-protected ZIP file.

Extract AES Encrypted ZIP Files in C#

A ZIP archive can also be encrypted with AES encryption. Aspose.ZIP for .NET supports encrypting archives with AES128, AES192, and AES256 encryption methods. Unzipping an AES encrypted ZIP file is similar to unzipping password-protected ZIP files. Just specify the decryption password using ArchiveLoadOptions class and rest will be taken care of by the API.

The following code sample shows how to extract AES encrypted ZIP files in C#.

C# ZIP Extraction API - Get a Free License

You can extract ZIP archives without evaluation limitations by getting a free temporary license.

Conclusion

In this article, you have learned how to unzip ZIP files using C#. Furthermore, you have seen how to extract password-protected ZIP archives in C#. The code samples have also demonstrated how to extract files in an encrypted ZIP archive in C#. You can explore more about Aspose.ZIP for .NET using documentation.

See Also