Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse a WebClient object to download the data at a URI in VB .NET
DescriptionThis example shows how to use a WebClient object to download the data at a URI in VB .NET.
KeywordsWebClient, URL, URI, download, VB .NET
CategoriesInternet, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated