Which method do you think is the \"best\".
System.IO.Packaging
namespace?The GZipStream and DeflateStream classes under System.IO.Compression namespace make it pretty easy to zip things up.
UPDATE: Comments correctly state that these classes do not allow you to manipulate a Zip file. However, the J# dlls contain the required functionality in java.util and java.io namespaces. For more details see the Code Project article by dmihailescu which details their use and provides sample code.
DotNetZip is very simple to use. I like it because it is fully-managed - no shell interaction required. The programming model is simpler and cleaner than that for the shell. Also it is simpler than SharpZipLib as well as the Packaging classes added in .NET 3.0. It is free, small, actively maintained.
It is much better than the J# option that one poster offered - J# is a huge runtime and a giant pill to swallow to get just ZIP support. Also J# support is being discontinued. Probably not a good idea to introduce new dependencies on J#.
Example code for DotNetZip:
try
{
using (ZipFile zip = new ZipFile(args[0], System.Console.Out))
{
zip.AddDirectory(args[1]); // recurses subdirectories
zip.Save();
}
}
catch (System.Exception ex1)
{
System.Console.Error.WriteLine("exception: " + ex1);
}
DotNetZip works with .NET v2.0, 3.0, 3.5 as well as Compact Framework v2.0 and 3.5. It does ZIP files, Unicode filenames, comments, passwords. It does ZIP64 as well as Self-extracting archives. It's FAST. Try it.
Since you're targetting Framework 3.5, I'd go with System.IO.Packaging
. It's a library designed specifically for zipping, and comes with the framework so there's not even an extra DLL needed by the product. The usage example is atrocious, though.
Using the shell is unrecommended. First, it would only work on Windows XP and above. But even if you don't care about that, it's pitfalls are quite numerous (I've done it before, but only because I really had no choice).
if you're not targetting 3.5, I'd use SharpZipLib. It's quite a good library, and even if you are using 3.5 you might consider it.
Ultimate ZIP is a high-performance and reliable compression component which lets you easily create and manipulate ZIP, TAR, TGZ, GZ archives on-the-fly as well as browse the contents of a previously created archive right in your .NET cross-platform apps. Written purely in C# with the best design patterns and low-level .NET optimizations applied, it offers performance, reliability and extensibility to your .NET applications. The package comes with a number of code snipets and fully documented examples in VB.NET and C# illustrating how to create, zip and unzip archives.
Ultimate ZIP component for .NET
I've always used SharpZipLib
Forgot the why part: Mainly because its been around for a long time. It is well documented, and has an intuitive API. Plus it's open source if you're into that type of thing.
No one has mentioned the Xceed Zip component. I've used it before and it worked excellent for creating zip files and compressing data streams. I highly recommend it but there may be a license fee tradeoff.