VB6 – Downloading a file

This post was written by Brandon on December 18, 2008
Posted Under: Visual Basics 6

To download a file through your application and save it is simple. This can be used to check for updates and download them with ease!

The code is simple, this code would download the "Gravity Example" from this post.

 
Dim bytes() As Byte
bytes() = Inet1.OpenURL("http://bncapps.com/wp-content/uploads/GravityTests-Bin+Scr.rar", icByteArray)
    ff = FreeFile
    Open App.Path & "/GravityTests-Bin+Scr.rar" For Binary As #ff
        Put #ff, , bytes()
   Close #ff
 

Note: The download link must be a direct link to the file or you will end up downloading the web page.

Be sure to have a INet control on your form or it will be unable to connect!
Also, if you dont want to save the file in the "app path" which is the current directory of the application, remove that part and simply make it:

 
Open "C:\Program Files\GravityTests-Bin+Scr.rar" For Binary As #ff
 

Hope this helps!

Add a Comment

required, use real name
required, will not be published
optional, your blog address

Previose Post: