Scripting.FileSystemObject.FileExists always returns false

I am trying to check if a file exists before including it in Server.Execute in classic ASP. Although FileExists () returns False, Server.Execute successfully executes the file. Both calls use the same file path.

Why is this happening and how can I get around it?

0


source to share


1 answer


I suspect you are passing a relative path (eg "/Subfolder/Page.asp"). You need Server.MapPath , which is called on FileExists - which requires an absolute path (eg "C: \ inetpub \ Wwwroot \ subfolder \ Page.asp").



<%
Dim path : path = "/Admin/default.asp"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(Server.MapPath(path)) Then
   Server.Execute(path)
Else
   Response.Write "The path " & path & " does not exist."
End If

Set fso = Nothing
%>

      

+2


source







All Articles