By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,033 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,033 IT Pros & Developers. It's quick & easy.

Opening a file over the internet

P: n/a
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,
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

Webclient.OpenRead

http://msdn.microsoft.com/library/de...nreadtopic.asp

Ken
------------------
"Adrian" <ab*****@noemail.nospam> wrote in message
news:73**********************************@microsof t.com...
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,
Nov 21 '05 #2

P: n/a
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
Nov 21 '05 #3

P: n/a
"Adrian" <ab*****@noemail.nospam> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.