Zipping files in C#

For a while ago I tried to create zip files to be used by windows built in zip functionality. Did try to use GZipStream but I found out that I needed a GZip expander installed to be able to use it. I don’t understand why we have an inbuilt function in VS to create a compressed format that Windows can’t open natively. Anyway after a lot of search I found DotNetZip. It has a really easy to use API and no dependencies to other DLL’s.

It supports the following 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

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);
}
0.00 avg. rating (0% score) - 0 votes

About Peter Wibeck

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

*