reading a text file from a URL

B

bj daniels

I have a text file at a particular URL (physical path is not part of the
website). Though I could link to the file and it would open - what I really
need to do is to be able to get the text in that file into a variable.

since the file is not part of the website I am working on (it is part of a
different virtual server), the mappath doesn't seem to be working. Here is
what I am trying (captionfile parameter is the full path (by url - but could
be by UNC or drive letter) to the .txt file):

thanks
bj daniels
----------------------
Public Function GetCaption(ByVal CaptionFile As String) As String
Dim result As String
Dim fs As New FileStream(Server.MapPath(CaptionFile), FileMode.Open,
FileAccess.Read)
'Dim fs As New FileStream(CaptionFile, FileMode.Open,
FileAccess.Read)

Dim objReader As New StreamReader(fs)

'result = "<pre>"
While objReader.Peek > -1
result += Server.HtmlEncode(objReader.ReadLine) & "<br>"
End While
'result += "</pre>"

objReader.Close()
fs.Close()
Return result
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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top