2010年12月22日 星期三

WebClient object to download the data at a URI in VB .NET

來源處
--
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

沒有留言:

張貼留言