Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FSO Help with access to a Text File?

Status
Not open for further replies.

Rock6431

Programmer
Mar 23, 2002
56
US

I am simply trying to open a txt file and read the contents of it from VBscript on my webpage. Can anyone help with this one? I get no results out on the msgbox.

Mike


p.s. vfile = "\\server\folder\filename.txt"


Function GetTEXT
On Error Resume Next

Dim fso4
Dim txfile
Dim fts
Dim ftext

err.clear

Set fso4 = CreateObject("Scripting.FileSystemObject")

If (fso4.FileExists(vfile)) Then
' Verification File Exists and We need to Read it...
Set txfile = fso4.OpenTextFile(vfile)
Set fts = txfile.OpenAsTextStream(ForReading)
ftext = fts.readline
MsgBox(ftext)
fts.Close

set txfile = nothing
set fso4 = nothing

Else
' File Doesn't Exist.
Alert("Unable to OPEN: No File Exists.")
Exit Function
End If

End Function
 
I'm no expert but try removing the 'OpenAsTextStream'
ie.
Set txfile = fso4.OpenTextFile(vfile)
ftext = txfile.readline

Note:
This will read the first line of the file only,
and the 'Alert' doesn't work on my system - MsgBox does
(Is Alert a valid function ?)
 
If you are in vbscript with late binding you cannot use the constants such as ForReading. You need to replace them with their actual numeric values, unless you declare the constants yourself. To get these values use VB with a reference to the FSO object and then use the debug window (i.e. ?ForReading).
 
Rock6431,

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, filename, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso_OpenTextFile(filename, ForAppending, True)


fengshui_1998
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top