Tag Archives: gzip

Add Zip, GZip, BZip2 and Tar; Compression/DeCompression in Visual Basic.NET

SharpZipLib is a library for DotNet that has been around for awhile and thought maybe someone would be looking to wanting to do Zip/Unzipping type support in .NET applications. It is a OpenSource library named: #ziplib or pronounced Sharp Zip Library. It is written in C# and you can get the source code for the entire library and/or simply download the compiled assembly. The library has assemblies compatible with ALL versions of the DotNET framework including v2.0 and VB. I tried out the FastZip method and it worked perfectly fine and made fully compatible zip files that even Windows could unzip. Below is some simple code I used. You should have no problems using this library in your Visual Basic 2005, VB 2008, or VB.NET 2010 programs.

First, you will obviously want to add a reference to the library. You can do that from the Project menu and click on the Add Reference item. Then Browse for the reference and when you find the compiled zip library, open that .dll as the reference. I selected v2.0 since I am using Visual Basic 2005. Then create a zip object from the library.

        'Create a nnew instance of the Sharpzip .net zipping library.
        Dim zLib As New ICSharpCode.SharpZipLib.Zip.FastZip

I then simply put the following code in a button…

        'The last parameter can be used if you only want certain files with the specified extensions will be zipped up.
        zLib.CreateZip("c:\zipFileToAddFilesTo.zip", "c:\whereToGetFilesFrom", False, ".exe")



That is all I did and was able to zip up all of the .exe based files from a specific directory and had them all in a single *.zip file.

Anyways, I only wanted to mention the existence of this library if you need/want a variety of compression methods. This library supports most of the popular formats and has many options and features you can use. Click this Link to go and read about and get the library if your interested.

Edit: Microsoft added a new Zip class with .NET Framework 4.5. So if you only want regular zip/unzip features, head over the MSDN site at this link.


Revised: 2015