Visual Studio ships with an assembly to compress and decompress files. This assembly is used in the Export Template feature for example.
The assembly is Microsoft.VisualStudio.Zip.9.0.dll and its located in the GAC.
The two main classes that we need to use are ZipFileCompressor and ZipFileDecompressor.
The API is really simple:
To compress a file:
var pathRoot = @”C:\MyPath”;
var files = Directory.GetFiles(pathRoot, “*.*”, SearchOption.AllDirectories);
files = files.Select(file => file.Replace(pathRoot, string.Empty)).ToArray();
// This doesn’t follow any design guidelines, but all the logic for compressing a list of files
// is in the constructor, so the only thing that we need to do to compress is to create an
// instance of ZipFileCompressor.
var comp =
newZipFileCompressor(@”C:\Foo.zip”, pathRoot, files, true);
To decompress a file:
var decomp = newZipFileDecompressor(@”C:\Foo.zip”);
decomp.UncompressToFolder(@”C:\Foo”, true);
Just zip it,
Pablo

