
Object required error with FSO
The Server object doesn't exist on the client side...
Even if you create your objFileObj correctly on the client (subject to browser security since it's
"unsafe"), you can't read server side files unless there is an accessible UNC path (or a
consistently mapped network drive path) to the file(s) on the server.
--
Michael Harris
MVP Scripting
I'm using a FileSystemObject to try to open a server-side text file to
write/read text from. I have set up a test with the following code:
<SCRIPT LANGUAGE="VBScript">
Const File_OpenForReading = 1
Const File_OpenForWriting = 2
Const File_OpenForAppending = 8
Function File_OpenExisting( strPath, nAccess )
' strPath = the path to file
' nAccess should be one of the constants above
On Error Resume Next
Dim objFileObj
Dim objFile
Set objFileObj = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileObj.OpenTextFile( strPath, nAccess, False, False )
If Err = 0 Then
Set File_OpenExisting = objFile
Else
Set File_OpenExisting = Nothing
End If
End Function
Sub ReadLineFromFile()
Dim oFile
Set oFile = File_OpenExisting("/files/refids.dat",File_OpenForReading)
While Not oFile.AtEndOfStream
alert(oFile.ReadLine()& "<br>")
Wend
oFile.Close
End Sub
</SCRIPT>
The Sub ReadLineFromFile() is called when I click on a button on the page
but as soon as I click on the button, I get an 'Error: Object required:
oFile'
If anyone knows what is going wrong then please help me.
TIA
J8ram