Search Wiki:

DotNetZip - Zip file manipulation in .NET languages

DotNetZip is a small, easy-to-use class library for manipulating .zip files. It can enable .NET applications written in VB.NET, C#, any .NET language, to easily create, read, and update zip files. It supports these kinds of scenarios:

- creating a zip archive, adding files or directories into the archive
- extracting files from an existing archive
- modifying an existing archive - removing entries from an archive or adding new entries to an archive
- password protecting entries in the archive
- getting entry input from a file or a stream
- reading a zip file from a file or a stream
- extracting an entry into a file or a stream

The library can be used in any .NET application - Console, Winforms, WPF, ASP.NET, Servers, and so on. It produces zip files that are fully interoperable with Windows Explorer, as well as Java applications, apps running on Linux.

It is designed to be simple and easy to use. DotNetZip is packaged as a single DLL, about 200k in size. It has no third-party dependencies. Get zipping just by referencing the DLL.

If you find DotNetZip useful, consider donating. I am now accepting donations on behalf of my favorite charity. and Yes, it is a real charity.

Background and Details

Example Usage
   try
   {
     using (ZipFile zip = new ZipFile("MyZipFile.zip")
     {
       zip.AddFile("c:\\photos\\personal\\7440-N49th.png");
       zip.AddFile("c:\\Desktop\\2005_Annual_Report.pdf");
       zip.AddFile("ReadMe.txt");
       zip.Save();
     }
   }
   catch (System.Exception ex1)
   {
     System.Console.Error.WriteLine("exception: " + ex1);
   }


Tons more examples on the Examples Page


Frequently Asked Questions


How does this Zip Library work?
There's a single DLL, a single assembly, fully managed code, written in C#, that provides support for reading and writing Zip archive files and streams. The main type is ZipFile, featuring Add() and Extract() methods, as well as an enumerator for the entries contained within.

What do I need to "do" zip files from within my application?
To use the zip capability in your applications, you need to be using the .NET Framework 2.0 or later, and you need the DotNetZip assembly. You can use the Zip library from any application, whether a console application, a Windows-Forms application, a server-based application like an ASP.NET page, or something else. You can use C#, VB.NET, COBOL.NET, IronPython, IronRuby, F#, or any other .NET language.

How big is the library?
As of version 1.4, the Ionic zip DLL is about 50k in size. The self-extracting stuff, added in v1.5 in June 2008, brought that to about 200k in size. There is just one DLL. There is no other pre-requisite.

Why would you want to produce yet another Zip Library?
There are a number of options in the .NET Ecosystem for manipulating zip files. Some are commercial libraries, some are open-source. You can even shoe-horn the System.IO.Packaging API, which is included in .NET 3.0, into a zip library. But there are tradeoffs for all of them. Some people don't want to pay for a commercially-supported library. Some people don't like the GPL. Most people want something simple and easy to use. This is one more option. It's fast, it's simple, it's free.

Does this library make self-extracting zip files?
Yes. As of v1.5, It can make self-extracting zip files. It also makes standard zip files.

Are the zip files this library makes compatible with the Java.util.zip classes in the Java class library?
Yes. This library makes standard zip files.

Can I use Windows Explorer to open the zip files that this library creates?
Yes. This library makes standard zip files.

Does the library support zero-length zip entries, zipfile comments, zip entry comments, and zipping up empty directories?
Yes.

If I create a zipfile with this library, can I open it from within a Java application, using the java.util.zip library?
Yes. This library makes standard zip files, so anything that can read and write zip files, on any platform, can work with zipfiles generated from this library.

Does this library support any compression algorithm other than deflate?
No. That is what is provided by the System.IO.Compression.DeflateStream class.

Why would I not just use the Packaging APIs included in the .NET Framework 3.0?
The Packaging APIs are optimized for producing .docx files and .xlsx files. This library is generally simpler and cleaner for creating or reading plain, generic zipfiles.

Does the library support reading or writing encrypted or password protected zip files?
Yes, in v1.4 of the library, available as of 25 May 2008. Your applications can now handle zip files that use passwords to protect the entries in the zip archive.

Does the library support Unicode filenames and comments?
No. Not yet anyway. I'm interested in taking contributions on that.

Is there documentation for the library?
Yes, there is a CHM file in MSDN helpfile format, generated from the xml comments in the code.

Does the library support zipping to a stream? Or unzipping from a stream?
Yes, this was added in v1.4 of the Library. This means you can zip up files and Save the zip archive to a stream. As well you can Read a zip archive from an open stream. This complements the capability of being able to Save to a plain .zip file or read from a plain .zip file, which was in the library since v1.1

Ok, you can unzip from a stream, and read a zip from a stream, But... can you add an entry to a zipfile grabbing content from a stream? Or can you unzip an entry to a stream?
Yes, this capability was added in v1.4.

Does this library allow removal of entries from zip files, or updating of entries in zip files?
Yes, this capability was added in v1.5.

What if I add an already-compressed file into a zip archive?
Yes, the library handles already-compressed data, such as .mp3 files or .jpg files, intelligently.

Is it just a library, or is there some other way I can take advantage of the DotNetZip?
The DotNetZip source download also includes example applications: command-line utilities that utilize the library, that you can use out of the box to zip and unzip.

Can I grab the source for DotNetZip and embed it into my own project?
Yes - that's allowed by the license.

Last edited Jun 20 at 6:41 AM  by Cheeso, version 27
Comments
aquinas wrote  Jun 27 at 5:16 PM  
Awesome. Thanks for this. I tried using SharpZipLib, but I couldn't get it to create ANY zips that java could read! Your interface is also a lot nicer to work with. Cheers!

Updating...