Hi guys,
Does anybody know how to read a text file from web server?
For example, read test.txt file from: http://abc/test.txt

Any comments will be highly appreciated.
Thanks

How to read a text file from web server by Tom

Tom
Mon Aug 25 14:11:13 CDT 2003

Here's one way ...

----------------8<-----------------
' Source Alex K. Angelopoulos, modified by TGL 14 Feb 2003
' http//groups.google.com/groups?selm=OxJBkB8xCHA.2120%
'40TK2MSFTNGP11

' Change this to point to a suitable location
Const sSavePath = ".\"

' Get URL for desired site
sPage = http://abc/test.txt

' Keep full URL for storage file, but replace slashes
sName = sSavePath & Replace(sPage, "/", "_")

' Get page
sData = GetXml(sPage)

'now save the page to a file.
WriteFile sName, sData

Wscript.Echo "Done"

Function GetXml(sURL)
' Create an xmlhttp object:
With CreateObject("Microsoft.XMLHTTP")
.open "GET",sURL
.send
Do:wscript.sleep 50:Loop While .ReadyState<>4
GetXml = .responseText
End With
End Function

Sub WriteFile(FilePath, sData)
'writes sData to FilePath
CreateObject("Scripting.FileSystemObject")._
OpenTextFile(FilePath, 2, True).Write sData
End Sub
----------------8<-----------------

Tom Lavedas
===========

>-----Original Message-----
>Hi guys,
>Does anybody know how to read a text file from web server?
>For example, read test.txt file from: http://abc/test.txt
>
>Any comments will be highly appreciated.
>Thanks
>
>.
>

How to read a text file from web server by Tom

Tom
Mon Aug 25 16:47:52 CDT 2003

That was a VBscript solution, as that is the newsgroup in
which I read your post. The main feature of the solution
is the use of the Microsoft.XMLHTTP, which can be
instantiated in exactly the same manner in VB as in script
or it can be early bound in a Dim statement, I believe (or
added to the object library for drag and drop
instatiation).

Writing the output to a file can be done using the
FileSystemObject, as in the script, or using the intrinsic
VB file manipulation methods (Open & Write).

The only part that can't be done as in the scripting
example is the Do/Wscript.Sleep/Loop. A Do Events
construct would be needed instead. I don't currently
program in VB, so I can't offer much more guidance than
that.

If you want better VB help, you'll need to go to a VB
specific group (if you haven't already).

Tom Lavedas
===========

>-----Original Message-----
>Thanks, buddy.
>Is there a way to do this in Visial Basic Project, not in
>an ASP or HTML file?
>
>
>>-----Original Message-----
>>Here's one way ...
>>
>>----------------8<-----------------
>>' Source Alex K. Angelopoulos, modified by TGL 14 Feb
2003
>>' http//groups.google.com/groups?selm=OxJBkB8xCHA.2120%
>>'40TK2MSFTNGP11
>>
>>' Change this to point to a suitable location
>>Const sSavePath = ".\"
>>
>>' Get URL for desired site
>>sPage = http://abc/test.txt
>>
>>' Keep full URL for storage file, but replace slashes
>>sName = sSavePath & Replace(sPage, "/", "_")
>>
>>' Get page
>>sData = GetXml(sPage)
>>
>>'now save the page to a file.
>>WriteFile sName, sData
>>
>>Wscript.Echo "Done"
>>
>>Function GetXml(sURL)
>> ' Create an xmlhttp object:
>> With CreateObject("Microsoft.XMLHTTP")
>> .open "GET",sURL
>> .send
>> Do:wscript.sleep 50:Loop While .ReadyState<>4
>> GetXml = .responseText
>> End With
>>End Function
>>
>>Sub WriteFile(FilePath, sData)
>> 'writes sData to FilePath
>> CreateObject("Scripting.FileSystemObject")._
>> OpenTextFile(FilePath, 2, True).Write sData
>>End Sub
>>----------------8<-----------------
>>
>>Tom Lavedas
>>===========
>>
>>>-----Original Message-----
>>>Hi guys,
>>>Does anybody know how to read a text file from web
>server?
>>>For example, read test.txt file from:
http://abc/test.txt
>>>
>>>Any comments will be highly appreciated.
>>>Thanks
>>>
>>>.
>>>
>>.
>>
>.
>

How to read a text file from web server by Fish

Fish
Tue Aug 26 08:56:03 CDT 2003

Thank you very much, Tom.
Your answer is exactly what i want.
Thanks again.

>-----Original Message-----
>That was a VBscript solution, as that is the newsgroup in
>which I read your post. The main feature of the solution
>is the use of the Microsoft.XMLHTTP, which can be
>instantiated in exactly the same manner in VB as in
script
>or it can be early bound in a Dim statement, I believe
(or
>added to the object library for drag and drop
>instatiation).
>
>Writing the output to a file can be done using the
>FileSystemObject, as in the script, or using the
intrinsic
>VB file manipulation methods (Open & Write).
>
>The only part that can't be done as in the scripting
>example is the Do/Wscript.Sleep/Loop. A Do Events
>construct would be needed instead. I don't currently
>program in VB, so I can't offer much more guidance than
>that.
>
>If you want better VB help, you'll need to go to a VB
>specific group (if you haven't already).
>
>Tom Lavedas
>===========
>
>>-----Original Message-----
>>Thanks, buddy.
>>Is there a way to do this in Visial Basic Project, not
in
>>an ASP or HTML file?
>>
>>
>>>-----Original Message-----
>>>Here's one way ...
>>>
>>>----------------8<-----------------
>>>' Source Alex K. Angelopoulos, modified by TGL 14 Feb
>2003
>>>' http//groups.google.com/groups?selm=OxJBkB8xCHA.2120%
>>>'40TK2MSFTNGP11
>>>
>>>' Change this to point to a suitable location
>>>Const sSavePath = ".\"
>>>
>>>' Get URL for desired site
>>>sPage = http://abc/test.txt
>>>
>>>' Keep full URL for storage file, but replace slashes
>>>sName = sSavePath & Replace(sPage, "/", "_")
>>>
>>>' Get page
>>>sData = GetXml(sPage)
>>>
>>>'now save the page to a file.
>>>WriteFile sName, sData
>>>
>>>Wscript.Echo "Done"
>>>
>>>Function GetXml(sURL)
>>> ' Create an xmlhttp object:
>>> With CreateObject("Microsoft.XMLHTTP")
>>> .open "GET",sURL
>>> .send
>>> Do:wscript.sleep 50:Loop While .ReadyState<>4
>>> GetXml = .responseText
>>> End With
>>>End Function
>>>
>>>Sub WriteFile(FilePath, sData)
>>> 'writes sData to FilePath
>>> CreateObject("Scripting.FileSystemObject")._
>>> OpenTextFile(FilePath, 2, True).Write sData
>>>End Sub
>>>----------------8<-----------------
>>>
>>>Tom Lavedas
>>>===========
>>>
>>>>-----Original Message-----
>>>>Hi guys,
>>>>Does anybody know how to read a text file from web
>>server?
>>>>For example, read test.txt file from:
>http://abc/test.txt
>>>>
>>>>Any comments will be highly appreciated.
>>>>Thanks
>>>>
>>>>.
>>>>
>>>.
>>>
>>.
>>
>.
>