If you’re looking to extract ZIP archives programmatically in C#, you’ve come to the right place! This article serves as a comprehensive guide on how to effectively handle ZIP file extraction using the .NET archive extraction library. We will explore various methods for unzipping files, including how to manage password-protected archives and AES encryption.

Extract ZIP Files in C#

In our previous article on creating ZIP files, we discussed different techniques for packaging files using Aspose.ZIP for .NET. Now, let’s dive into unzipping ZIP files and extracting files from both password-protected and AES encrypted ZIP archives in C#.

Table of Contents

Extract ZIP Archives in C# - API Installation

Before we get started, ensure that you have downloaded and referenced Aspose.ZIP for .NET. You can also install the package via the NuGet Package Manager. To add the library to your project, run the following command:

PM> NuGet\Install-Package Aspose.Zip

How to Extract ZIP Files in C#

Extracting ZIP files can be accomplished in two primary ways:

  1. Extract each file from the ZIP archive individually.
  2. Unzip all files into a specified folder.

C# Extract Each File in ZIP

To extract files individually while monitoring the extraction progress, follow these steps:

Here’s a code sample demonstrating how to extract files from a ZIP archive in C#:

Unzip ZIP Files into a Folder in C#

If you prefer to unzip all files into a specific folder, follow these steps:

Here’s a code sample for unzipping ZIP files into a folder:

C# Unzip Password-Protected ZIP Files

You can extract password-protected ZIP archives using Aspose.ZIP for .NET. Simply specify the password using the ArchiveLoadOptions class, which you will pass as the second parameter to the Archive’s constructor.

Here’s a sample code snippet for unzipping a password-protected ZIP file:

Extract AES Encrypted ZIP Files in C#

If your ZIP archive is encrypted with AES, Aspose.ZIP for .NET supports AES128, AES192, and AES256 encryption methods. Extracting an AES encrypted ZIP file is similar to unzipping a password-protected archive; you only need to provide the decryption password using the ArchiveLoadOptions class.

Here’s how to extract AES encrypted ZIP files in C#:

C# ZIP Extraction API - Get a Free License

You can perform ZIP extraction without any evaluation limitations by obtaining a free temporary license.

Conclusion

In this article, we’ve covered how to unzip ZIP files using C# and tackled the extraction of password-protected ZIP archives. Additionally, we explored how to handle encrypted ZIP files. For more information on using Aspose.ZIP for .NET, check out the documentation.