Skip to Main Content
How to Zip and UnZip a file in .NET C# in seconds!

How to Zip and UnZip a file in .NET C# in seconds!

How to Zip and UnZip a file in .NET C# in seconds!

Xceed Zip for .NET makes manipulating Zip files in C# very easy and simple.

First launched in 2002 for .NET 1.0, Xceed Zip for .NET has been updated frequently ever since by our developers. It allows to quickly Zip and Unzip files using C# or Visual Basic for .NET code. 

Note that the following example is done in C#, but that the Visual Basic for .NET code will be very similar.

Also note that this code is compatible with .NET Standard, .NET Core, .NET 5 and .NET 6. Should you have an older project that also needs help from Xceed Zip for .NET, it is also compatible with all legacy versions of the .NET Framework. 

So let's get to it!

There are 2 ways we can go about compressing. The easiest way is to use our QuickZip class.

If your scenarios are simple, this may just be the solution you need:

Xceed.Zip.QuickZip.Zip(@"c:ResultZipZippedFile.zip", true, true, false, @"c:FilesToZip*.*");

To find all the different options and parameters related to this class, go here: https://doc.xceed.com/xceed-filesystem-for-net/topic9402.html

As you just saw, you can create a zip archive from a file or folder using just 1 line of code. Isn't that fantastic!

Xceed Zip for .NET is pretty much limitless and is very flexible. Here's a more complex example:


//Zip Archive Approach
ZipArchive zipFile = new ZipArchive(new DiskFile(@"c:ResultZipZippedFileArchive.zip"));
DiskFolder folder = new DiskFolder(@"c:FilesToZip");
folder.CopyFilesTo(zipFile, true, true);

 

To UnZip, simply do the operations in reverse. It really is that simple and easy!

Xceed.Zip.QuickZip.Unzip(...)

Same as the Zip Archive approach, but this time you do the reverse operations:

ZipArchive zipFile = new ZipArchive(new DiskFile(@"c:ResultZipZippedFileArchive.zip"));
DiskFolder folder = new DiskFolder(@"c:FilesToZip");
zipFile2.CopyFilesTo(folder , true, true);

Xceed Zip for .NET offers a ton more functionalities! If you need more information, all functionalities are documented here (including encryption and different compression algorithms): https://doc.xceed.com/xceed-filesystem-for-net/webframe.html#topic87.html

Happy coding! 

 

Join more than 100,000 satisfied customers now!

IBM
Deloitte
Microsoft
NASA
Bank of America
JP Morgan
Apple