Making and reading ZIP Files in .NET

So you want to use the zip file format in your .NET 2/3/3.5 application? There is a compression namespace in .NET 2.0, of course; but it doesn't do zip, only deflate and GZIP (so you can't have multiple files in one archive).

So to date I've always used the venerable SharpZipLib, written for .NET 1.1 but which still converts cleanly to newer versions and does the job.

Well what I found out today is that there is actually an example in the Windows Vista SDK! When it's installed in the default location you will find it in a zip file called "Framework Samples" in C:\Program Files\Microsoft SDKs\Windows\v6.0\Samples; within that zip file there is a folder called Applications\CompressionSample and it is available in both C# and VB.NET.

There are a couple of limitations that I know of; namely it won't compress files that are already compressed very well (and may end up making them larger); and it won't compress files larger than 4Gb. (Tell me if you know of any others...) For a better experience, you'll need to buy a component from a third party. :-)