tags:

views:

1553

answers:

2

I'm attempting to check that a file exists before including it with Server.Execute in Classic ASP. While FileExists() returns False, Server.Execute successfully executes the file. Both calls use the exact same file path.

Why does this happen and how can I work around it?

A: 

Are you using a Network Path? If so, try without that, perhaps mapping a drive.

BobbyShaftoe
Mapped drives are not available in ASP
AnthonyWJones
+2  A: 

I suspect you're passing a relative path (eg., "/Subfolder/Page.asp"). You'd need to Server.MapPath that for the call into FileExists - which needs 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
%>
Mark Brackett