How can I load a web page into a variable?

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I simply want to read a webpage and save it to a variable using the dotnet
framework.

I am a competent vb.net programmer, just this simple task is beyond me!!!
Any suggestions as to which class library to use would be gratefully
received.

Regards
Steve
 
Dim wr As HttpWebRequest =
CType(WebRequest.Create("http://www.fruitsalad.org/people/mdouhan/test/foo.t
xt"), HttpWebRequest)

Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)

Dim str As Stream = ws.GetResponseStream()

Dim inBuf(100000) As Byte

Dim bytesToRead As Integer = CInt(inBuf.Length)

Dim bytesRead As Integer = 0

While bytesToRead > 0

Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)

If n = 0 Then

Exit While

End If

bytesRead += n

bytesToRead -= n

End While
 
I simply want to read a webpage and save it to a variable using the dotnet
framework.

\\\
Imports System.IO
Imports System.Net
..
..
..
Public Function LoadTextFile(ByVal Url As String) As String
Dim wrq As WebRequest = WebRequest.Create(Url)
Dim wrp As HttpWebResponse = _
DirectCast(wrq.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = _
New StreamReader(wrp.GetResponseStream)
Dim Text As String = sr.ReadToEnd()
sr.Close()
wrp.Close()
Return Text
End Function
///
 
Back
Top