Get started with IronZIP

Start using IronZIP in your project today with a free trial.

First Step:
green arrow pointer


Create an Archive Example

To create a ZIP archive object, you can conveniently use the using statement in C# along with the IronZipArchive constructor. IronZip makes this process straightforward, allowing you to establish an empty ZIP archive with just a few lines of code.

Next, utilize the Add method to import your files into the ZIP archive. This method allows you to add files from various locations, including an entire directory where all the files within it will be included.

Lastly, use the SaveAs method to export the ZIP file.

:path=/static-assets/zip/content-code-examples/tutorials/create-read-extract-zip-create.cs
using IronZip;

// Create an empty ZIP
using (var archive = new IronZipArchive())
{
    // Add files to the ZIP
    archive.Add("./assets/image1.png");
    archive.Add("./assets/image2.png");

    // Export the ZIP file
    archive.SaveAs("output.zip");
}
$vbLabelText   $csharpLabel

Unarchive an Archive to Folder

To retrieve the contents from a ZIP file, you can use the ExtractArchiveToDirectory method. Simply indicate the path of the target ZIP file and the directory where you want the extracted files to be placed.

:path=/static-assets/zip/content-code-examples/tutorials/create-read-extract-zip-extract.cs
using IronZip;

// Extract ZIP
IronZipArchive.ExtractArchiveToDirectory("output.zip", "extracted");
$vbLabelText   $csharpLabel

Add Files to An Existing Archive

You can efficiently modify an existing ZIP archive with additional files using IronZip. The process begins by instantiating the ZIP archive object from an existing ZIP file path. Once the archive is opened, you can use the Add method to add files to the existing archive.

:path=/static-assets/zip/content-code-examples/tutorials/create-read-extract-zip-add-files.cs
using IronZip;

// Open existing ZIP
using (var archive = IronZipArchive.FromFile("existing.zip"))
{
    // Add files
    archive.Add("./assets/image3.png");
    archive.Add("./assets/image4.png");

    // Export the ZIP file
    archive.SaveAs("result.zip");
}
$vbLabelText   $csharpLabel

With this functionality, you can efficiently update and expand your ZIP archives to suit your project's evolving needs. IronZip makes the process of managing archives in your C# projects a breeze.

A similar approach can be achieved for other archive and compression formats such as TAR, GZIP, and BZIP2 using the IronTarArchive, IronGZipArchive, and IronBZip2Archive classes, respectively.

Frequently Asked Questions

How do I create a ZIP archive using IronZip in C#?

To create a ZIP archive, use the IronZipArchive class. Utilize the Add method to include files and the SaveAs method to save the archive. Example code: `using (var zip = new IronZipArchive()) { zip.Add(@"C:\path\to\directory"); zip.SaveAs(@"C:\path\to\output.zip"); }`.

How can I read the contents of a ZIP file with IronZip?

To read a ZIP file, you can open it using the IronZipArchive class by passing the file path to the constructor. This allows you to access the ZIP's contents for viewing or extracting specific files.

How do I extract files from a ZIP archive using IronZip?

Use the ExtractArchiveToDirectory method to extract files. Specify the ZIP file path and the destination directory. Example: `using (var zip = new IronZipArchive(@"C:\path\to\archive.zip")) { zip.ExtractArchiveToDirectory(@"C:\path\to\output\directory"); }`.

Can I add more files to an existing ZIP archive with IronZip?

Yes, open the existing ZIP using IronZipArchive, utilize the Add method to include additional files, and then save the updated archive with SaveAs.

What are the steps to get started with IronZIP?

To get started, download the IronZip library from NuGet, instantiate IronZipArchive to create a ZIP, and use methods like Add and ExtractArchiveToDirectory to manage ZIP archives.

Is it possible to manage other archive formats with IronZip?

Yes, similar methods can be used for other formats like TAR, GZIP, and BZIP2 using IronTarArchive, IronGZipArchive, and IronBZip2Archive classes.

Where can I find the IronZip library for C#?

The IronZip library can be downloaded from NuGet. Visit the package page to download and integrate it into your C# projects.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.