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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FSO.GetFile causes my server to hang

Status
Not open for further replies.

AlexNeil

Programmer
Jun 4, 2001
49
GB
Hi,

I have IIS running on Windows 2000. I am trying to open a text file using VBScript within my ASP code, but the GetFile method causes the server to hang. Here's the code extract:-

Code:
<%
  Function ReadHTMLFile()
    Dim objFSO
    Dim objFile
    Dim strFileName

    strFileName = Chr(34) & _
      Server.MapPath(&quot;/MyWebDev/sample1.txt&quot;) & _
      Chr(34)

    Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    Set objFile = objFSO.GetFile(strFileName)
  End Function
%>

I have surrounded the filename by quotes (&quot;) because it contains spaces.

Any ideas??

Alex
 
take out the quotes, and see what happens. I think the quotes are what's giving you an error.

Try
strFileName = cstr(Server.MapPath(&quot;mywebdevs/sample1.txt&quot;))

Also - make sure that you don't have On Error Resume Next...
it makes it a whole lot easier to debug.

good luck
leo
 
Cheers Leo,

I tried your line (i.e without surrounding quotes) but unfortunately I still get the same problem; the server just hangs.

I haven't used any error handling, so I would've thought that I'd just get some error raised.

thanks,
Alex
 
You are in ASP. You must use Server.CreateObject not CreateObject. I wouldn't hurt to intercept errors.
Code:
Dim lngErr
Dim strError
    Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
    On Error Resume next
        Set objFile = objFSO.GetFile(strFileName)
        lngErr = Err.Number
       if lngErr <> 0 then strError = Err.Desciption
    On error goto 0
    if lngErr <> 0 then
    ....
    End if
 
Hi, thanks for your help so far. I've incorporated the changes suggested, and the code now appears as below -- but the &quot;Set objFile = ...&quot; line still hangs!

Do you have any ideas?

cheers, Alex
Code:
<%
  Function ReadHTMLFile()
    Dim objFSO
    Dim objFile
    Dim objReader
    Dim strFileName
    Dim lngErr
    Dim strError

    strFileName = cstr(Server.MapPath
                    (&quot;mywebdevs/sample1.txt&quot;))
    Set objFSO = Server.CreateObject
                    (&quot;Scripting.FileSystemObject&quot;)
    On Error Resume Next
      Set objFile = objFSO.GetFile(strFileName)
      lngErr = Err.Number
      If lngErr <> 0 then strError = Err.Desciption
    On Error Goto 0
    If lngError = 0 Then
      ReadHTMLFile = &quot;GetFile Ok&quot;
    Else
      ReadHTMLFile = strError
    End If
  End Function
%>
 
Alex,

Did you get this code to run? I am having the exact same problem and would appreciate knowing what you discovered.

Thanks,

Bob Collins
 


AlexNeil,

Have your tried running the code outside the ASP script to see if an error occurs. The only things you need to change is the Server.MapPath and Server.Create.

If that works, then it might be a permissions problem.

fengshui_1998
 
I have exact the same problem. I'm working on 2 server, staging server and live server. Everything's absolutely fine on the staging server but it doesn't work on live server.

There is no error message or anything... just hangs.

I think it's a permission problem.

But, does anyone know how to fix this problem?

Cheers
Gib
 
Hi,

I have similar problem but my server hangs at

Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

This is the only row in my ASP file (excluding <% and %>).
Unfortunately disable the Script Blocking does not help.

vamosb
 
Finally found a solution to this!

I installed the Service Packs 1 and 2 (I'm running Windows 2000) and that has solved the problem.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top