Object required error with FSO 
Author Message
 Object required error with FSO

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



Tue, 19 Nov 2002 03:00:00 GMT  
 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



Tue, 19 Nov 2002 03:00:00 GMT  
 Object required error with FSO
Quote:
> 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

Quote:
> "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.

So how can I access text files on the server side?

TIA

J8ram



Tue, 19 Nov 2002 03:00:00 GMT  
 Object required error with FSO

Quote:

> Dim oFile
> Set oFile = File_OpenExisting("/files/refids.dat",File_OpenForReading)

>  While Not oFile.AtEndOfStream

One reason is that if the file does not exist then your
File_OpenExisting returns a "nothing"  to oFIle so the
oFile.AtEndOfStream fails.

Steve



Wed, 20 Nov 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Error 424 (Object required) when creating an object - ???

2. Automation error... Error 424, Object Required

3. Error Starting application executable (error 424 - Object required)

4. "Object Required" error

5. Error : Object Required

6. VBscript - Error 424 Object Required - NEED a FIX

7. runtime error 800a01a8, Object Required: 'Application(...)'

8. Object required error

9. Error Code 424- Object Required

10. Object Required Error

11. "Object Required" error

12. Getting Object Required error

 

 
Powered by phpBB® Forum Software