Using the Inet Control

Downloading the file

On Error Resume Next

If strURL = "" Then
    Status = "URL not provided"
    Exit Function
End If

With Form1.Inet1

    .URL = strURL
    bytes() = .OpenURL(, icByteArray)

    strResult = .OpenURL(strURL, icString)

    'Essential to avoid tying up the system
    Do Until .StillExecuting = False ' WAIT Downloading..
        DoEvents
    Loop
End With

We have used the OpenURL method of the control to retrieve the content from the remote file. The easiest way to use the Internet Tranfer Control is with the OpenURL method. Two parameters are passed to this method. The first parameter is the URL of the file to be downloaded and the second parameter is the datatype which will tell the control about the datatype of the content to be downloaded from the remote server. This can be text or binary. If you want to download file from a FTP server then the URL parameter should contain something like this:

ftp://ftp.server.com/test.htm

In case of HTTP, provide the URL in the format shown below:

http://www.server.com/image1.gif

Datatype is the type of data being retrieved, this can be text or binary. The values that can be provided to this parameter are as following:

  • icString
    Use this type if you want to download the data as a string.
  • IcByteArray
    Use this datatype if you want to download the data as a binary.

We have used the URL property of the control to assign the URL of the file to be downloaded to the control. We have used the OpenURL method twice, first time, to retrieve the actual data and second time to retrieve the data as a text. I know this is an inefficient way but I did this just for demonstration purposes. The data is retrieved as a text because the first 50 chars of the downloaded string contain the error messages, if any.

Do Until .StillExecuting = False ' WAIT Downloading..
    DoEvents
Loop

Lets bring our focus to the statement above, what we are doing is checking the status of the control, this is important as we want the system to wait for the control to complete the transfer. If "StillExecuting" is true then it means that the control is still busy downloading the file.

You might also like...

Comments

About the author

S.S. Ahmed United States

S.S. Ahmed is a senior IT Professional and works for a web and software development firm. Ahmed is a Microsoft Office SharePoint Server MVP. Ahmed specializes in creating database driven dynamic...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold