Reading/Writing zip files with C#

Ok so today I found myself having to read/write from a zip file in C#. Apparently in the 2.0 framework this is built in. You need to use the GZipStream class found in the System.IO.Compression namespace.

You can read more here on MSDN

After a bit more research I have found the GZipStream class is pretty limited. You would be better served to look at the Sharp Zip Library. It's a GPL project so if you have issues with that read their disclaimer/legal pages. I have used it and have been able to read/write zip files made with windows xp and win zip.

You can read more here

UPDATE: I suggest using DotNetZip from CodePlex you can get it here. It's a snap to use and generates zip files for .net very easily and quickly.

Get it from CodePlex Some sample code for DotNetZip
 using (ZipFile zip = new ZipFile())
     // 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");


Unknown said…
I used dotnetzip library to read zip files. But I did not get accurate results for most of the zip files. I only got Ionic.Zip.ZipException :Cannot read that as a zip file for most of the zip files.

Popular posts from this blog

C# Form Application in Kiosk Mode/Fullscreen

C# using a transaction with ODBC

Notify Icon Text vs BalloonTipText