Name

FileExists — objTools.FileExists (strPath)

Synopsis

The FileExists method, as its name implies, allows you to determine whether a given file exists on the server. This method returns -1 if the file exists and the URL represents a published directory. It returns a otherwise.

Parameters

strPath

The relative URL of the file whose existence you are testing.

Example

<HTML>
<HEAD><TITLE>Latest Submitted Stories</TITLE></HEAD>
<BODY>
Below is a link to the latest science fiction story submitted to our site:<BR>
<% 
' This script assumes that elsewhere in the site, users are allowed to ' 
' submit stories which are then written as a file to a published directory.

' Check for existence of file first, before writing the link.
Set objTools = Server.CreateObject("MSWC.Tools")
If objTools.FileExists("/userstories/story.html") = -1 Then
%>
<A HREF="/userstories/story.html">Latest Science Fiction Story</A>
<%
Else
%>
Sorry. No story available.
<%
End If
%>
</BODY>
</HTML>

Notes

This method is useful if you need to create a link on the fly to a file that may or may not exist. For example, if your website allows users to add content (through some template or otherwise) and that content is stored on the server, you may want to determine whether that file exists before creating a link to it.

Note that this method is functionally equivalent to the FileExists method of the FileSystemObject component.

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.