|
|
Title | Use a WebClient object to download the data at a URI in VB .NET |
Description | This example shows how to use a WebClient object to download the data at a URI in VB .NET. |
Keywords | WebClient, URL, URI, download, VB .NET |
Categories | Internet, VB.NET |
|
|
When you enter as URI and click the Upload button, the program creates a WebClient object. It uses the object's OpenRead method to open the URI for reading, attaches a StreamReader to the stream, uses its ReadToEnd method to read the data, and displays the result.
|
|
Private Sub btnUpload_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnFetch.Click
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
Try
' Make a WebClient.
Dim web_client As WebClient = New WebClient
' Get the indicated URI.
Dim response As Stream = _
web_client.OpenRead(txtURI.Text)
' Read the result.
Dim stream_reader As New IO.StreamReader(response)
txtResults.Text = stream_reader.ReadToEnd()
' Close the stream reader and its underlying stream.
stream_reader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Read Error", _
MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation)
End Try
Me.Cursor = Cursors.Default
End Sub
|
|
|
|
|
|