Opening a file over the internet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My final goal is to laod the source of an HTML page displayed at a given URL
and through a buffer to save it into a database. If that file would be local,
the code would be:

Dim fs As FileStream
Dim sPath as String = "C:\Test.htm"
fs = File.OpenRead(sPath)
Dim buffer(fs.Length) As Byte
fs.Read(buffer, 0, fs.Length)

and from buffer I would insert that file into the database.
My problem is that File.OpenRead() does not accept as argument an URL.
Could someone help me figure how can I read the source of a WEB page (as a
HTML file) in order to save it into my database.

Thanks in advance,
 
Hi,

Webclient.OpenRead

http://msdn.microsoft.com/library/d...frlrfsystemnetwebclientclassopenreadtopic.asp

Ken
------------------
My final goal is to laod the source of an HTML page displayed at a given URL
and through a buffer to save it into a database. If that file would be
local,
the code would be:

Dim fs As FileStream
Dim sPath as String = "C:\Test.htm"
fs = File.OpenRead(sPath)
Dim buffer(fs.Length) As Byte
fs.Read(buffer, 0, fs.Length)

and from buffer I would insert that file into the database.
My problem is that File.OpenRead() does not accept as argument an URL.
Could someone help me figure how can I read the source of a WEB page (as a
HTML file) in order to save it into my database.

Thanks in advance,
 
Adrian,

As alternative
\\\\
Module main
Public Sub main()
Dim myReg As Net.HttpWebRequest = _
DirectCast(Net.WebRequest.Create("http://www.google.com"), _
Net.HttpWebRequest)
Dim myResp As Net.HttpWebResponse = _
DirectCast(myReg.GetResponse(), Net.HttpWebResponse)
Dim myStream As IO.Stream = myResp.GetResponseStream()
Dim myreader As New IO.StreamReader(myStream)
Dim mystring As String = myreader.ReadToEnd()
myResp.Close()
End Sub
End Module
///
I hope this helps a little bit?

Cor
 
Adrian said:
My final goal is to laod the source of an HTML page displayed at a given
URL
and through a buffer to save it into a database. If that file would be
local,
the code would be:

Dim fs As FileStream
Dim sPath as String = "C:\Test.htm"
fs = File.OpenRead(sPath)
Dim buffer(fs.Length) As Byte
fs.Read(buffer, 0, fs.Length)

and from buffer I would insert that file into the database.

\\\
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 New StreamReader(wrp.GetResponseStream)
Dim Text As String = sr.ReadToEnd()
sr.Close()
wrp.Close()
Return Text
End Function
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top