Zip files and folders in .NET

A lot of solutions exists that show how to zip files in .NET, for example some of them using SharpZipLib, GZipStream, Windows Shell API or the ZipLibrary class. However one lesser known solution which I have found to be very useful is the DotNetZip library

As given on the site - “DotNetZip is an easy-to-use FREE class library and toolset for manipulating zip files or folders. Zip and Unzip is easy: with DotNetZip, .NET applications written in VB, C# - any .NET language - can easily create, read, extract, or update zip files. It works on Mono or MS .NET”

You can download DotNetZip Library over here.

Here’s a sample that shows how to use this library to zip all files in a folder


using System;
using Ionic.Zip;

namespace ZipSample
class Program
static void Main(string[] args)
using (ZipFile zip = new ZipFile())
Console.WriteLine("Files zipped");
catch (ZipException ex)


Imports System
Imports Ionic.Zip

Namespace ZipSample
Class Program
Shared Sub Main(ByVal args() As String)
zip As New ZipFile()
Console.WriteLine("Files zipped")
End Using
ex As ZipException
End Try
End Sub
End Class
End Namespace
Depending on the size of the files in a folder, it may take some time for the zip operation to complete.

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

1 comment:

Radhika Vinod said...

Very Useful.. Thank you so much for reducing my effort :)