# 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#, or any .NET language, to easily create, read, and update zip files. Zip Compression is easy with DotNetZip. The DotNetZip project also includes a library for performing ZLIB, Deflate, or GZIP compression and decompression, a library for BZip2 compression and decompression, a GUI ZIP tool, and a few command line tools.

DotNetZip works on Windows-powered PCs with the full .NET Framework, and also runs on Windows Mobile devices that use the .NET Compact Framework. Create and read zip files in VB, C#, or any .NET language. The library can also be used from COM enironments, like PHP, Classivc ASP, or VBSCript. DotNetZip supports these scenarios:

- creating a zip archive, adding files or directories into the archive
- listing files in an archive, extracting files from an archive
- modifying an existing archive - renaming entries, removing entries from an archive, or adding new entries to an archive
- creating zip files from stream content, saving to a stream, extracting to a stream, reading from a stream
- dynamically creating ZIP files from ASP.NET or Silverlight applications

If all you want is a better DeflateStream or GZipStream class to replace the one that is built-into the .NET BCL, that is here, too. DotNetZip's DeflateStream and GZipStream are available in a standalone assembly, based on a .NET port of Zlib. These streams support compression levels and deliver much better performance that the built-in classes. There is also a ZlibStream to complete the set (RFC 1950, 1951, 1952).

This 100% managed code library can be used in any .NET application - Console, Winforms, WPF, ASP.NET, Sharepoint, Web services apps, Powershell scripts, 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 400k in size. It has no third-party dependencies. It is Medium Trust, so can be used on most hosters. Get zipping just by referencing the DLL. The library supports zip passwords, Unicode, ZIP64, stream input and output, AES encryption, multiple compression levels, self-extracting archives, and more.

The release includes the library, as well as some sample applications (with source) showing how to use the library.

## DotNetZip is DonationWare

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.

## Example Usage

      using (ZipFile zip = new ZipFile("MyZipFile.zip")
      {
        zip.AddFile("c:\\images\\personal\\7440-N49th.png");
        zip.AddFile("c:\\Desktop\\2008-Regional-Sales-Report.pdf");
        zip.AddFile("ReadMe.txt");
        zip.Save();
      }

Tons more examples on Codeplex, and later in this helpfile.

## Frequently Asked Questions

How does this Zip Library work?
DotNetZip is packaged as a single DLL, a single assembly. It is fully managed code, written in C#, and provides support for reading and writing Zip archive files and streams. The main type is ZipFile, featuring methods like Add(), Extract() and Save(). There are string and int indexers for the entries of the ZipFile. There are properties for things like password protection, unicode and codepage support, and ZIP64 behavior. And there are progress events for Reading, Saving, and Extracting.

What do I need, in order to be able to create and read zip files from within my application using this library?
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.

What do I need to build this library from the source?
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, a smart-device app, a Windows Service, or something else. You can use C#, VB.NET, COBOL.NET, IronPython, IronRuby, F#, or any other .NET language. You can use the full version of Visual Studio, or one of the Visual Studio Express tools, or just a text editor.

What if I just want to use the graphical tool?
No problem. Just download the Utils download from the latest releases tab, and you will get an easy-to-use fully-functional ZIP creation and extraction tool, a free functional-equialent replacement for WinZip. It supports all the DotNetZip capability, like SFX, AES, ZIP64, arbitrary Code Pages, Unicode, zip comments, file and entry selection, and more.

What do I need to _build_ this library from the source?f
You need the .NET Framework SDK v3.5, or later; or, Visual Studio 2008 or later. While the library is usable by .NET 2.0 and later, to build it you need .NET 3.5 or later. This is because the source code uses features that were introduced in the C# v3.0 compiler, vars and array initializers and so on. The .NET 3.5 SDK is available here. I don't know if the library will _build_ in Visual C# Express 2008; I never tried it. It should.

How big is the library?
As of version 1.9, the Ionic zip DLL is about 420k in size. The self-extracting capability comprises about 200k of that. There is a "Reduced" build of the library in the Developer's Kit, that eliminates the SFX capability and results in a DLL of about half the size. The Compact-Framework version of the library is about 130k. 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 world 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 are willing to give up commercial support for a lower price. Some people don't like the GPL. Some of those other packages are complex to use for zip files. Some of them don't have enough features (Eg, AES encryption, ZIP64). Some are too slow. What I found is that most people want something simple and easy to use, that works well, has good features, compresses effectively and fast, and is the right price. DotNetZip is that option. It's fast, it's simple, it's free.

Does this library make self-extracting zip files?
Yes. It can make self-extracting zip files or standard zip files. The self-extracting archives can either be Windows (GUI) apps or command-line applications. The self-extractors require .NET 2.0 on the computer doing the extraction.

Does this library read self-extracting zip files?
Yes. As of v1.7, DotNetZip can read self-extracting zip files generated by WinZip. As of v1.8 (currently in preview), DotNetZip can read SFX archives generated by itself. DotNetZip does not (yet) read SFX archives built by some other tools. I've not tested it.

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. If you use some advanced features not supported by the built-in Java library, like AES encryption or ZIP64, then the zip files won't be readable by Java. This is a shortcoming in Java, not in DotNetZip.

If I create a zipfile with this library, can I open it from within a Java/PHP/Python/C/Perl application? From within WinRar/WinZIP?
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. In Java, you would use the java.util.zip library. In Python, you would use the zipfile module. Keep in mind that not all languages and environments support all ZIP features. For example, currently the Java library does not do ZIP64, and the zipfile module in Python does not support zipfile comments, while DotNetZip can create and read zip archives using those features. You need to be careful with interop testing. If you don't know what these features are, you probably don't need them and you won't run into interop problems.

If I create a zipfile with a java/PHP/Python/C/Perl application, or with WinRar/WinZip/7zip, can I open it from within a .NET application, using this library?
Yes. This library reads compliant zip files.

Can I use Windows Explorer to open the zip files that this library creates, and vice versa?
Yes. This library reads and writes standard zip files. If you use extensions to the ZIP spec not supported by Windows, like ZIP64 or AES encryption, Windows Explorer will not be able to extract the files.

Does the library work with applications that depend on the .NET Compact Framework?
Yes. DotNetZip is built for the .NET Compact Framework (v2.0 or later) as well as for the regular .NET Framework (v2.0 or later). This means you can build a Smart Device application in Visual Studio 2008, that uses the capabilities of DotNetZip.

Does the library support zero-length zip entries, zipfile comments, zip entry comments, zipping up empty directories, recursive directory traversal, zipping up selected files by filename (with wildcards), and password-protecting entries?
Yes.

Does the library handle ZIP64?
Yes. This was added in December 2008 in v1.7. The original ZIP specification allowed up to 65535 entries in a zip archive, and archive and entry sizes up to 4.2g. The ZIP64 extensions raise those restrictions, at the expense of compatibility and interoperability. DotNetZip can read or write "standard" zip files or ZIP64 zip files.

Does this library support any compression algorithm other than deflate?
No. Entries are either Stored or Deflated.

Does this library use System.IO.Compression.DeflateStream for the DEFLATE algorithm?
No. In earlier versions, it did. But the DeflateStream built-into the .NET Framework BCL exhibits anomalous compression behavior on previously compressed data, like mp3 or jpg files. DotNetZip includes a managed compression library, based on ZLIB. It's fast, fully DEFLATE compliant, and it compresses better than the built in version! And, the DeflateStream that is included in DotNetZip is available for any application to use, under the same terms as the rest of the DotNetZip library.

Why would a developer 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. Also this library takes advantage of ZIP features like ZIP64 or AES, in a much nicer way. And it provides nice features like progress events and file selectors.

Does the library support reading or writing encrypted or password protected zip files?
Yes, this library helps applications read and write zip files that use passwords to protect the entries in the zip archive. Either PKZIP ("weak") encryption or WinZip-compatible AES encryption.

Can Windows Explorer ("compressed folders") read and extract the zip files created by this library if the zip has password protection?
Yes. It just works.

Can I use the DotNetZip library to read .docx files, .xslx files?
Yes. They are just zip files. Keep in mind, the Packaging APIs included in .NET 3.0 are optimized for producing .docx files and .xlsx files.

Does the library support Unicode filenames and comments?
Yes, as of September 2008, the library can create and read zip files that have Unicode (UTF-8) filenames and comments. You can also specify arbitrary code pages when reading or writing zipfiles. But, Windows Explorer does not support UTF-8 encoded zip files. To read the zip you create, you will have to use a tool or library that supports unicode, such as WinRar, DotNetZip, etc.

Can the library be used to read a zip file that has entries with filenames containing Chinese characters, as produced by WinRAR?
Yes. To do this you would specify the "big5" code page (cp 950) when reading the zip. In addition to Chinese, it can handle any code page.

What about reading and writing zip files with other languages and code pages? Portugese? Hebrew? Arabic? Greek? Cyrillic? Norwegian? Finnish? etc?
Yes. Just specify the appropriate code page when reading or writing the zip archive.

Can Windows Explorer ("compressed folders") read the zip files created by this library if the zip has entries with Unicode-encoded filenames?
No. But that is a limitation of Windows XP and Windows Vista. It is not a limitation of this library.

Is there documentation for the library?
Yes, there is a CHM file in MSDN helpfile format, generated from the xml comments in the code. All the public interfaces are thoroughly documented. There are tons of code examples in the doc.

Does the library support zipping to a stream? Or unzipping from a stream?
Yes, 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 - I use this for embedded resources in apps: I call GetManifestResourceStream(), and then unzip that resource. Reading and writing streams complements the capability of being able to Save to a plain file or read from a plain file. The Save-to-a-stream capability allows you to write a zip archive out to, for example, the ASP.NET Response.Output stream, without creating an intermediate file. Very nice for ASP.NET applications.

Ok, the library can write a zip archive to a stream, and read a zip from a stream, But... can the library add an entry to a zipfile, grabbing content from a stream? can the library unzip a single entry into a stream? Can an application read an entry as a stream?
Yes. Yes. Yes. Unlike some other libraries, in most cases DotNetZip handles the streaming; your application does not need to implement a Read/Write data pump. The application needs only to open the streams. Using the stream support, you could, for example, open a zip archive, and then modify the files in the archive, and Save out to a Response.OutputStream in ASP.NET, without ever writing a file to the disk. All the zip file content can be maniulated in memory (using MemoryStream for example).

Does this library allow removal of entries from zip files, or updating of entries in zip files?
Yes.

Do I have to write programs to take advantage of this thing? or is there some other way I can take advantage of the DotNetZip?
Typically people will embed this DLL into an application. But, the DotNetZip downloads includes a package of "example" applications: command-line utilities that utilize the library, that you can use out of the box to zip and unzip. I drop these in my own bin directory and it allows me to zip and unzip from the command line or from batch files. Also, you can take advantage of the DotNetZip library from within Powershell, if that is your bag. Creating or extracting zips within a script is pretty handy.

Can I grab the source for DotNetZip and embed it into my own project?
Yes - that's allowed by the license. But you may want to think about just redistributing the binary DLL - it is a much easier option.

Can I distribute the binary DLL with my own project?
Yes - that's allowed by the license.

What's the mainstream approach for using DotNetZip in a 3rd party app?
The mainstream approach is to distribute the binary DLL with your own app.

What if I want to use DotNetZip in my app, but I don't want to distribute it as a separate DLL?
You have options. The most mainstream and generally easiest way to embed DotNetZip into your application is to redistribute the DLL. But if you don't want to do that, there are alternatives. One option is to embed the source for DotNetZip into your own project. This may seem like the obvious approach, but it is probably not what you want, unless you really need to modify the source of DotNetZip. A better approach is to merge the DLL into your EXE, with ILMerge. This works with your app regardless of what language it uses, whether it is a Winforms app, a WPF app, a service, etc.