Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2007
    Posts
    219
    Thanks
    25
    Thanked 1 Time in 1 Post

    asp plain text file error

    I've got asp installed on the intranet server of the firm i work for.
    Now I want to open a plain text file on a network drive of that server.
    However when I try the script below I get the following error:

    c:\inetpub\wwwroot\test.asp
    File /test.asp does not exist

    How can I solve this ?

    <%@language="vbscript"%>
    <% Option Explicit

    Const Filename = "/test.asp" ' file to read

    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

    ' Create a filesystem object
    Dim FSO
    set FSO = server.createObject("Scripting.FileSystemObject")

    ' Map the logical path to the physical system path
    Dim Filepath
    Filepath = Server.MapPath(Filename)
    response.write(filepath)

    if FSO.FileExists(Filepath) Then

    Set TextStream = FSO.OpenTextFile(Filepath, ForReading, False, _
    TristateUseDefault)
    ' Read file in one hit

    Dim Contents
    Contents = TextStream.ReadAll
    Response.write "<pre>" & Contents & "</pre><hr>"
    TextStream.Close
    Set TextStream = nothing

    Else

    Response.Write "<h3><i><font color=red> File " & Filename &_
    " does not exist</font></i></h3>"

    End If

    Set FSO = nothing
    %>

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Code works fine on my server.

    Does your anonymous (INET_USR) account have read and run scripts access to \wwwroot\ on the server?

    Also, since you are using OPTION EXPLICIT, make sure you dim TextStream.

    Code:
    <%@language="vbscript"%>
    <% Option Explicit
    
    Const Filename = "/test.asp" ' file to read
    
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    
    ' Create a filesystem object
    Dim FSO
    set FSO = server.createObject("Scripting.FileSystemObject")
    
    ' Map the logical path to the physical system path
    Dim Filepath
    Filepath = Server.MapPath(Filename)
    response.write(filepath)
    
    if FSO.FileExists(Filepath) Then
    
    Dim TextStream
    Set TextStream = FSO.OpenTextFile(Filepath, ForReading, False, TristateUseDefault) ' Read file in one hit
    
    Dim Contents
    Contents = TextStream.ReadAll
    Response.write "<pre>" & Contents & "</pre><hr>"
    TextStream.Close
    Set TextStream = nothing
    
    Else
    
    Response.Write "<h3><i><font color=red> File " & Filename &_
    " does not exist</font></i></h3>"
    
    End If
    
    Set FSO = nothing
    %>
    Last edited by Daemonspyre; 04-10-2007 at 07:31 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •