DotNetZip is a library for handling zip files in .NET applications. To use DotNetZip, you can follow these general steps:

Download and Reference:

Download the DotNetZip library from the official website or install it using a package manager like NuGet.

Reference the DotNetZip assembly in your project.

NuGet Package Manager:
Install-Package DotNetZip

Using DotNetZip in Code:

Import the Ionic.Zip namespace in your code.
using Ionic.Zip;

Creating a Zip File:

To create a new zip file, you can use the ZipFile class.

using (ZipFile zip = new ZipFile())
{
 zip.AddFile("file1.txt", "");
 zip.AddFile("file2.txt", "");
 zip.Save("archive.zip");
}

Extracting Files from a Zip:

To extract files from a zip file, use the ZipFile.ExtractAll method.

using (ZipFile zip = ZipFile.Read("archive.zip"))
{
 zip.ExtractAll("extracted-folder");
}

Adding Files to an Existing Zip:

You can add files to an existing zip file using the ZipFile.AddFile or ZipFile.AddEntry methods.

using (ZipFile zip = ZipFile.Read("existing-archive.zip"))
{
 zip.AddFile("new-file.txt", "");
 zip.Save();
}

Working with Password-Protected Zips:

To create or extract files from a password-protected zip, set the Password property.

using (ZipFile zip = new ZipFile())
{
 zip.Password = "secure-password";
 zip.AddFile("file1.txt", "");
 zip.Save("encrypted-archive.zip");
}

// Extracting
using (ZipFile zip = ZipFile.Read("encrypted-archive.zip"))
{
 zip.Password = "secure-password";
 zip.ExtractAll("extracted-folder");
}

Support On Demand!

.Net