Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / Visual Basic

DotNetZip

Rate me:
Please Sign up or sign in to vote.
4.17/5 (5 votes)
13 Apr 2011CPOL1 min read 75.4K   11   8
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:

VB
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
This article was originally posted at http://morrisbahrami.blogspot.com/feeds/posts/default

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Australia Australia
I have over 17 years of experience in software development in a variety of fields. For last 7 years the emphasis has been mostly on .NET technology (C# and VB.NET) which includes WPF, WCF and ASP.NET AJAX. Also have SQL Server experience including SSIS and SSRS. My blog (http://morrisbahrami.blogspot.com) has a collection of tips and general info for Microsoft Developers.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Bill Gross Tech20-Mar-14 6:55
Bill Gross Tech20-Mar-14 6:55 
Questionhttp://stackoverflow.com/questions/19173395/adding-a-zip-file-to-zip-file Pin
SureshKuParser Error4-Oct-13 5:20
SureshKuParser Error4-Oct-13 5:20 
AnswerRe: http://stackoverflow.com/questions/19173395/adding-a-zip-file-to-zip-file Pin
Morris Bahrami4-Oct-13 14:02
Morris Bahrami4-Oct-13 14:02 
QuestionZip count Pin
Pramod Kamath21-Sep-13 2:24
Pramod Kamath21-Sep-13 2:24 
AnswerRe: Zip count Pin
Morris Bahrami22-Sep-13 20:08
Morris Bahrami22-Sep-13 20:08 
QuestionThe file 'c:\DotNetZip\Zip\ZipFile.cs' does not exist. Pin
BobSunndb13-Dec-11 7:38
BobSunndb13-Dec-11 7:38 
AnswerRe: The file 'c:\DotNetZip\Zip\ZipFile.cs' does not exist. Pin
Morris Bahrami13-Dec-11 12:02
Morris Bahrami13-Dec-11 12:02 
GeneralMy vote of 5 Pin
El-ahrairah23-May-11 8:46
El-ahrairah23-May-11 8:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.