How to Create, Read, and Extract A Zip File in C#

In this tutorial, we delve into using the Iron Zip Library to manage ZIP files in C. The video begins by instructing viewers to set up a C console application in Visual Studio and install the Iron Zip Library using the NuGet Package Manager.

With the library installed, viewers learn to create an empty ZIP file using the IronArchive class, setting the stage for adding content. Files can be added using the AddArchiveEntry method, accommodating files from various directories. The tutorial also covers extracting files with the ExtractArchiveToDirectory method, demonstrating how to specify the ZIP file and destination folder. For existing ZIP files, the FromFile method allows adding more files, highlighting the flexibility of the Iron Zip Library.

The tutorial concludes by showcasing the results, with output files successfully generated and extracted. This hands-on guide emphasizes the ease and efficiency of managing ZIP archives in C projects, encouraging users to explore the library further through a trial available on the Iron Software website.

Below is a sample code that demonstrates the use of the Iron Zip Library for these tasks. It's important to ensure you have included the necessary library references in your project to execute the sample code successfully.

// C# - Sample code illustrating basic use of the Iron Zip Library

using IronZipLibrary; // Import the Iron Zip Library namespace

class ZipExample
{
    static void Main()
    {
        // Create a new empty ZIP file
        using (var archive = new IronArchive("myArchive.zip"))
        {
            // Add a file to the ZIP archive
            archive.AddArchiveEntry(@"C:\path\to\your\file.txt");

            // Extract all files to a specified directory
            archive.ExtractArchiveToDirectory(@"C:\destination\directory");
        }

        // Open an existing ZIP file and add another file to it
        using (var archive = IronArchive.FromFile("myArchive.zip"))
        {
            archive.AddArchiveEntry(@"C:\path\to\another\file.txt");
        }
    }
}
// C# - Sample code illustrating basic use of the Iron Zip Library

using IronZipLibrary; // Import the Iron Zip Library namespace

class ZipExample
{
    static void Main()
    {
        // Create a new empty ZIP file
        using (var archive = new IronArchive("myArchive.zip"))
        {
            // Add a file to the ZIP archive
            archive.AddArchiveEntry(@"C:\path\to\your\file.txt");

            // Extract all files to a specified directory
            archive.ExtractArchiveToDirectory(@"C:\destination\directory");
        }

        // Open an existing ZIP file and add another file to it
        using (var archive = IronArchive.FromFile("myArchive.zip"))
        {
            archive.AddArchiveEntry(@"C:\path\to\another\file.txt");
        }
    }
}
' C# - Sample code illustrating basic use of the Iron Zip Library

Imports IronZipLibrary ' Import the Iron Zip Library namespace

Friend Class ZipExample
	Shared Sub Main()
		' Create a new empty ZIP file
		Using archive = New IronArchive("myArchive.zip")
			' Add a file to the ZIP archive
			archive.AddArchiveEntry("C:\path\to\your\file.txt")

			' Extract all files to a specified directory
			archive.ExtractArchiveToDirectory("C:\destination\directory")
		End Using

		' Open an existing ZIP file and add another file to it
		Using archive = IronArchive.FromFile("myArchive.zip")
			archive.AddArchiveEntry("C:\path\to\another\file.txt")
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

Further Reading: Create, Read, and Extract Zip Tutorial

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.

Ready to get started? Version: 2025.6 just released

View Licenses >