IRONSOFTWAREHOME
COMPARE TO OTHER COMPONENTS

Zip Archive Tutorial for C# Developers Using IronXL

Curtis Chau
Curtis Chau
Updated: August 1, 2026

Introduction to ZipArchive

Whenever you think of sending a file over in a compressed format, the first thing that comes to mind is usually a Zip Archive. A zip archive is a popular format for compressing and packing a single file or an entire collection in a single archive. However, when there are large volumes of files to zip, working with them might become frustrating as you would have to archive and format them one by one. But it doesn't have to be like that. Large-volume tasks need automation to be done programmatically. We can use IronZIP, a simple yet intuitive library, to achieve all that and more.

In this article, we'll briefly discuss IronZIP's core features and functionalities and how it can help you better automate your workflow, increase efficiency, and eliminate error-prone manual tasks.

Creating a new zip file from a folder or files

Below is an example that takes in multiple files, zips them into one archive, and exports them after the operation. All examples in this article are encased in the static void Main() method to avoid repeated code blocks.

using IronZip;

class Program
{
    static void Main(string[] args)
    {
        // Create an empty ZIP archive
        using (var archive = new IronZipArchive())
        {
            // Add files to the ZIP archive
            archive.Add("./assets/image1.jpg");
            archive.Add("./assets/image2.jpg");
            archive.Add("./assets/image3.jpg");

            // Export the ZIP archive to a file
            archive.SaveAs("output.zip");
        }
    }
}
  1. We first import IronZIP.
  2. Then, using IronZIP, we create an archive.
  3. We call archive.Add() to add multiple files to the archive. Remember that path names must be absolute paths, or the operation will fail to find the corresponding files.
  4. Finally, we call archive.SaveAs() to export the zip archive as output.zip.

Updating an existing zip file with new files or modifications

Let's go over another example; this time, we will edit the existing zip archive with new files to showcase the functionality of IronZIP.

using IronZip;

class Program
{
    static void Main(string[] args)
    {
        // Open an existing ZIP archive
        using (var archive = IronZipArchive.FromFile("existing.zip"))
        {
            // Add additional files to the existing ZIP archive
            archive.Add("./assets/image3.png");
            archive.Add("./assets/image4.png");

            // Export the updated ZIP archive to a new file
            archive.SaveAs("result.zip");
        }
    }
}
  1. We first import IronZIP.
  2. Using IronZIP, we create an archive, but this time, we import the existing zip file with IronZipArchive.FromFile().
  3. We call archive.Add() to add the desired files to the archive. Remember that path names must be absolute paths, or the operation will fail to find the existing files.
  4. Finally, we call archive.SaveAs() to export the updated zip archive as result.zip.

As you can see from the code above, the operation and format are similar to those used to create and add files to a Zip file. The main difference is that we import the zip file instead, showcasing IronZIP's simple yet intuitive functionality.

Extracting files from a Zip archive

We can also use IronZIP to extract files from a Zip archive or Zip package. Let's review this in another example.

using IronZip;

class Program
{
    static void Main(string[] args)
    {
        // Extract the ZIP archive content to a specified directory
        IronZipArchive.ExtractArchiveToDirectory("output.zip", "extracted");
    }
}

We import IronZIP and call IronZipArchive.ExtractArchiveToDirectory(). This method extracts the contents of the existing zip archive to the specified target directory.

Furthermore, in cases where you need to deal with password-protected zip archives, we can use another method to extract the archives.

using IronZip;

class Program
{
    static void Main(string[] args)
    {
        // Extract the protected ZIP archive content to a specified directory
        IronZipArchive.ExtractArchiveToDirectory("output.zip", "extracted", "P@ssw0rd");
    }
}

Ultimately, we pass in another parameter: the password for the protected zip archive. The rest of the operation is the same as shown above.

Advanced Topics and Best Practices

The code examples for adding, extracting, and creating archives discussed above are the most common when dealing with zip archives. However, for more advanced usage, such as extracting other formats or simply viewing the archive's contents, IronZIP has you covered and more.

Advanced Features of IronZIP

  • Cross-compatibility: IronZIP is compatible with a wide range of .NET versions, including .NET Core (3.1+), Standard (2.0+), and .NET Framework (4.6.2+). The library also works on the Web (Blazor), Mobile (MAUI), Desktop (WPF), and Console. This allows developers to transcend platform and version limitations.
  • Generating Archives: Beyond the ZIP format, IronZIP supports creating TAR, GZIP, and BZIP2 archives.
  • Extracting Archives: Extract archives and decompress files easily with IronZIP using a single block of code, as demonstrated above.
  • Adding Files and File Systems: IronZIP assists in manipulating zip archives by adding images, text files, and documents (such as PDFs, DOCX, and XLSX), as well as audio files like MP3 and WAV. It can even compress entire file systems or individual text files into a ZipArchive archive.
  • Export and Create: You can password-protect archives with AES128 and AES256 standards. Additionally, you can generate and export formats like TAR, GZIP, and BZIP2.
  • Custom Compression Levels: IronZIP allows developers to adjust compression settings to fine-tune the algorithm to their needs.
  • Editing Archives: Easily add, extract, or delete file entries in an archive using IronZIP as a comprehensive solution for editing-related operations.
  • File Entry Properties: IronZIP provides the ability to set optional archive comments and retrieve file names within the archive without extracting them, aiding in leaving specific comments for each file.
  • Licensing Choices: IronZIP offers adaptable licensing choices, including complimentary trial versions, allowing developers to select what suits their requirements best.

Conclusion

Dealing with compressed files and archives is a daily task that developers often face, but managing a large volume of them can be stressful and prone to human error. Although there are options like System.IO.Compression, using IronZIP allows you to achieve more and quickly resolve issues when dealing with compressed archives. In this article, we discussed the advanced features of IronZIP and common operations like creating zip archives, deleting entries, or adding files. Understanding how to perform these tasks programmatically with IronZIP leads to increased efficiency, scalability, and automation in handling archives.

Please note: System.IO.Compression is a registered trademark of its respective owner. This site is not affiliated with, endorsed by, or sponsored by System.IO.Compression. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing.
Curtis Chau
Technical Writer

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.

...
Read More

Related Articles

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required