C# Tutorial: Create, Read & Extract ZIP Files
Create ZIP generates a new ZIP archive by selecting files or directories, specifying compression settings, and creating the archive.
Extract ZIP retrieves contents by specifying the source ZIP file, the destination folder, and extracting files and directories to the specified location.
In addition to these functions, IronZIP can also open an existing ZIP file, add more files to it, and then export the result as a new ZIP file containing all the included files.
Quickstart: Create or Extract a ZIP with IronZIP EasilyGet started fast - create, modify, or extract ZIP archives using IronZIP in just a few simple API calls. Perfect for developers who want to instantly work with archives without boilerplate.
-
1Install IronZIP with NuGet Package Manager
-
2Copy and run this code snippet.
IronZipArchive.ExtractArchiveToDirectory("project.zip", "outputFolder");C# -
3Deploy to test on your live environment
Start using IronZIP in your project today with a free trial
Minimal Workflow (5 steps)
- Download the C# library to create, read, and extract ZIP files
- Instantiate the IronZipArchive class to create an empty ZIP file
- Use the
Addmethod to add files to the empty ZIP - Utilize the
ExtractArchiveToDirectorymethod to extract the ZIP - Open an existing ZIP file by passing the ZIP file path to the constructor
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 adds a single file at a time; call it once per file you want to include.
Lastly, use the SaveAs method to export the ZIP file.
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");
}Imports IronZip
' Create an empty ZIP
Using 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")
End UsingUnarchive 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.
using IronZip;
// Extract ZIP
IronZipArchive.ExtractArchiveToDirectory("output.zip", "extracted");Imports IronZip
' Extract ZIP
IronZipArchive.ExtractArchiveToDirectory("output.zip", "extracted")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.
using IronZip;
// Open existing ZIP
using (var archive = new IronZipArchive("existing.zip"))
{
// Add files
archive.Add("./assets/image3.png");
archive.Add("./assets/image4.png");
// Export the ZIP file
archive.SaveAs("result.zip");
}Imports IronZip
' Open existing ZIP
Using archive = New IronZipArchive("existing.zip")
' Add files
archive.Add("./assets/image3.png")
archive.Add("./assets/image4.png")
' Export the ZIP file
archive.SaveAs("result.zip")
End UsingWith 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 file in C# using IronZIP?
You can create a ZIP file in C# using IronZIP by instantiating the IronZipArchive class, adding files with the Add method, and then exporting the archive with the SaveAs method.
What methods are available in IronZIP to extract ZIP files?
IronZIP provides the ExtractArchiveToDirectory method, which allows you to specify the source ZIP file and the destination folder to extract files easily.
Can I add files to an existing ZIP archive using IronZIP?
Yes, IronZIP allows you to open an existing ZIP file and use the Add method to include more files before re-exporting the archive.
Does IronZIP support other formats besides ZIP?
Yes, IronZIP supports other formats such as TAR, GZIP, and BZIP2 through the IronTarArchive, IronGZipArchive, and IronBZip2Archive classes, respectively.
What is the minimal workflow for using IronZIP in a C# project?
The minimal workflow involves downloading the IronZIP library, instantiating IronZipArchive, adding files using the Add method, and extracting archives with the ExtractArchiveToDirectory method.
How can I use a single line of code to extract a ZIP file with IronZIP?
You can extract a ZIP file in one line using IronZIP with the following code: IronZipArchive.ExtractArchiveToDirectory("project.zip", "outputFolder").
Is it possible to modify an archive without creating a new one from scratch?
Yes, you can modify an existing ZIP archive by opening it with IronZipArchive, adding new files, and saving the updated archive with SaveAs.
How does IronZIP simplify the creation of a ZIP archive in C#?
IronZIP simplifies ZIP archive creation by using straightforward methods like Add and SaveAs, enabling developers to manage file compression efficiently within a few lines of code.
What are the key steps to extract a ZIP file using IronZIP?
Key steps include calling the ExtractArchiveToDirectory method, where you specify paths for the source ZIP file and target extraction directory for file placement.
Can I use IronZIP for compression tasks other than ZIP?
Yes, for other compression tasks, IronZIP supports formats like TAR, GZIP, and BZIP2 by utilizing respective classes such as IronTarArchive, IronGZipArchive, and IronBZip2Archive.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.