Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Download web content using internet transfer control

0.00/5 (No votes)
11 Jul 2012 1  
An article that shows the usage of Internet Transfer Control

Sample Image - sshot.jpg

In this simple article, I would like to shed light on Internet Transfer Control which is shipped with the current version of VB (Version 6.0). The intended audience of this article is beginners who have just jumped into this vast field of internet development. We all know that internet is used for transferring data, so it’s pretty easy to figure out what the “Internet Transfer Control” does. With this control data can be transferred using either FTP or HTTP protocol. In this article, we will have a look at the working of the control with both HTTP and FTP protocols. I will walk you through the code step by step and will discuss each line of code.

The code accompanying this article is very simple and was written to demonstrate the working of ITC. You can continue to do research on your own once this article gets you started. The program in the code could retrieve data from HTTP and FTP Servers.

Creating the application

Start a new exe project and from the components menu (Press Ctrl + T) select Microsoft Internet Transfer Control 6.0 and Microsoft Rich Textbox Control 6.0.

1. Add the internet transfer control to your form.
2. Add the rich text box to the form. Change the name property to txtURL and the text property to www.microsoft.com or whatever you want the default download location to be.
3. Add a control array of two command buttons. Change the caption property of the button with index 0 to Go and of the other button to Quit.

Here is the code that is executed when the user clicks the Go button:

Private Sub Command1_Click(Index As Integer)

Select Case Index
Case 0:
If txtURL.Text <> "" Then
RichTextBox1.Text = Inet1.OpenURL(txtURL.Text, icString)
End If

Case 1:	
End
End Select
End Sub

As you can see from the code that we have used the openurl method of the inet control. OpenURL method has the following syntax:

Inet1.OpenURL (URL, DataType)

URL is the full URL that you want to open; it can be either HTTP or FTP protocol. Datatype is the type of data that you want to retrieve, it can be byte or string. The two values are icString (the default, value=0) and icByteArray (value=1).
The return value of the OpenURL method is the data returned by the URL. This method operates synchronously, which means that the program pauses until the data transfer is complete. The synchronous nature of OpenURL is important.

That’s it folks, this is all you need to retrieve text from the remote site. Save the project and run it. Enter the URL from where you want to download the html text in the text box (txtURL) and press Go.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here