Pablo Galiano : Zip and unzip with VS

Subscriptions

<September 2010>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

News

Subscribe to Pablo Galiano by Email

Post Categories

Zip and unzip with VS

 

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

posted on Thursday, July 03, 2008 11:32 AM by pga

# re: Zip and unzip with VS @ Wednesday, July 09, 2008 4:55 AM

It seems to be cool but i can't find Microsoft.VisualStudio.Zip.9.0.dll in my disk elsewhere except in GAC and i don't know how to reference a GAC assembly from VS.
I know how to do it in command line but it's not so easy...

MuiBiencarlota

# re: Zip and unzip with VS @ Wednesday, July 09, 2008 4:55 AM

It seems to be cool but i can't find Microsoft.VisualStudio.Zip.9.0.dll in my disk elsewhere in GAC and i don't know how to reference a GAC assembly from VS.
I know how to do it in command line but it's not so easy...

MuiBiencarlota