On a recent project I was asked to provide a real easy way to zip multiple files and while I have seen this problem solved many moons ago in VB6 I have never really thought about this question from a managed framework standpoint. While navigating MSDN I came across GZipStream but this did not explicitly provide an interface for adding files to a zip archive. Several Bings later I came across a highly rated project on CodePlex called DotNetZip.

I must say this got straight to the point, with a intuitive API that was well documented and explained. Here is a code sample:

using (ZipFile zip = newZipFile()
{
    // add this map file into the "images" directory in the zip archive
   
zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
    // add the report into a different directory in the archive
   
zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
    zip.AddFile("ReadMe.txt");
   zip.Save("MyZipFile.zip");
}

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.

Technorati Tags: