Home All Groups Group Topic Archive Search About

Opening a file over the internet

Author
2 Apr 2005 1:03 AM
Adrian
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,

Author
2 Apr 2005 1:12 AM
Ken Tucker [MVP]
Hi,

        Webclient.OpenRead

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetwebclientclassopenreadtopic.asp

Ken
------------------
"Adrian" <abcdefg@noemail.nospam> wrote in message
news:730843A9-88C1-4C8C-9333-31E4E573DD1A@microsoft.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,
Author
2 Apr 2005 6:43 AM
Cor Ligthert
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
Author
2 Apr 2005 11:16 AM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Adrian" <abcdefg@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/>