Downloading file and extracting ZIP compressed file with Visual Basic.NET

Posted by Daniel - 2,007 Views

vbnet,vbnet zip library,download file with vb.net,extracting zip file with vbnetThese are a couple examples of many simplified processes provided by the VB.NET. You can’t find these simplicity in its predecessor, the Traditional VB6.

Downloading a file - Believe it or not you only need less than 3 lines to download a file somewhere from the internet to you local drive. This sub procedure below can do that for you, without a reference to any library - it’s a built-in feature:

Private Sub DownloadFile(ByVal strURL As String, ByVal strSavePath As
String)
Dim objDL As New System.Net.WebClient
objDL.DownloadFile(strURL, strSavePath)
End Sub

And the sample procedure call is below. It will download SimpleGridBuilder, one the the averagecoder’s free collection to your C:\ path:

Call DownloadFile(“http://www.averagecoder.net/” _
&“wp-content/uploads/simplegridbuilder.zip”“c:\simplegridbuilder.zip”)

Extracting a zip file - You need vsjlib installed on your system in order to be able to extract a zip file. This library can be found in the distribution of the Visual J#. Installing Visual J# will also install the vsjilib into you IDE.

After you had the vsjlib installed, you can do anything you want with java.util.zip.ZipEntry class. But for simplicity you can find a wrapper class on the internet such as the Matthew Hood’s class - the clsDWDZip.vb.

Do the following steps to include that wrapper class into your project:

  1. Download the clsDWDZip.vb
  2. Place it in the same folder of your project files folder
  3. From the VB.NET IDE, choose [Project]-[Add Existing Item…] Menu then select the clsDWDZip.vb

The following sub procedure can be used to perform ZIP extracting process in collaboration with the clsDWDZip.vb:

Private Sub ExtractZIPFile(ByVal strSourcePath As String, ByVal strExtractTo As String)
Dim objZipFile As New DWDZip.DWDZipFile
objZipFile.FilePath = strSourcePath
objZipFile.Open()
objZipFile.ExtractAllTo(strExtractTo)
End Sub

You can download the example project included in this article or if you need more alternatives, there is also a good information from MSDN. Click here to go there.

Download the example project (65 KB)

share this article

Digg del.icio.us Netscape StumbleUpon Yahoo! MyWeb reddit Furl Magnolia Newsvine Technorati SlashDot Blinklist Simpy Google
This post as PDFPosted in: Programming - January 2008


Leave a Reply


Options for your comment:





Hi, my name is Daniel Nugraha, a single male live on an island called Java, Indonesia. This is the place for me to share my interest in computer programming.

Coffee Break

Comments - Thanks Guys :)

  • Rangga Kusuma: Gan, Tengkiu buat postingan yang sangat berguna. Kebetulan ada project utk bikin sms gateway, dan converter Agan sangat berguna utk...
  • Chuck Norton: I actually went ahead & bolted over to Justin’s Get The Image plugin here: http://justintadlock.com/ar...
  • Chuck Norton: Question: is it possible to insert something like [custfieldimg=”joice1.jpg,15 0,1:1″] into the actual templates instead of...
  • Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
  • tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.