If you’re looking to extract ZIP archives programmatically in C#, you’re in the right place! This article provides a straightforward guide on how to efficiently handle ZIP file extraction using the .NET framework zip extraction library. We’ll cover methods for unzipping files, including how to deal with password-protected archives and AES encryption.

Extract ZIP Files in C#

In our previous article on creating ZIP files, we explored various ways to package files using Aspose.ZIP for .NET. Now, let’s delve into unzipping ZIP files and extracting files from password-protected or AES encrypted ZIP archives in C#.

Table of Contents

Extract ZIP Archives in C# - API Installation

Before we start, ensure that you have downloaded and referenced Aspose.ZIP for .NET or installed the package via the NuGet Package Manager. You can easily add the library to your project with 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 and monitor 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 also 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.

See Also