...

View Full Version : asp plain text file error



docock
04-10-2007, 04:55 PM
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
%>

Daemonspyre
04-10-2007, 07:26 PM
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.



<%@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
%>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum