65.9K
CodeProject is changing. Read more.
Home

DotNetZip

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.17/5 (5 votes)

Apr 13, 2011

CPOL

1 min read

viewsIcon

76548

How to include zip/unzip functionality in your .NET applications.

If you want to include zip/unzip functionality in your .NET applications, a very good approach would be using DotNetZip (http://dotnetzip.codeplex.com). Recently, I needed this functionality in an installer application. I know I could use the freely available zip applications such as 7-zip on the development site to zip some files, but when it came to unzipping on the client site, I couldn’t assume that they have that third party application on their computer to unzip the files.

.NET comes with two classes which, at first, may seem suitable for zip/unzipping, but on a closer look, they turn out to be not what you may want. The System.IO.Compression class is intended to be used for one file, not a collection of files, and it does not exactly create Zip files. System.IO.Packaging is also not suitable for typical zip/unzipping. It is intended for working with Open Packages. It adds some XML files to the package in addition to the files you specify.

DotNetZip is an Open-Source project that delivers the zip/unzip functionality in a very easy way to use. You add the DLL (ionic.zip.dll) to your project and then you can zip files within a directory, just like this:

Dim zipFileName As String = “MyZipFile.zip”

Dim fileNames As String() = Directory.GetFiles(txtStorageDirectory.Text)

Using zip As Ionic.Zip.ZipFile = New Ionic.Zip.ZipFile
    For Each file In fileNames
        zip.AddFile(file)
    Next
    zip.Save(zipFileName)
End Using