ASP 101 - Active Server Pages 101 file_exists.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
	Dim strFileThatExists As String = "file_exists.aspx"
	Dim strFileThatDoesnt As String = "file_doesnt.aspx"
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
		litFileThatExists.Text = DoesFileExist(strFileThatExists)
		litFileThatDoesnt.Text = DoesFileExist(strFileThatDoesnt)
	End Sub
    Function DoesFileExist(strFileName As String) As Boolean
		Dim strFullPath As String
		' If we don't have a full path starting with a drive letter
		' then we run the path through Server.MapPath().
		If InStr(strFileName, ":") <> 0 Then
			strFullPath = strFileName
		Else
			strFullPath = Server.MapPath(strFileName)
		End If
		DoesFileExist = File.Exists(strFullPath)
	End Function
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Checking If A File Exists ASP.NET Sample</title>
</head>
<body>
<form id="myForm" runat="server">
	<p>
	<strong>Inline Code Version:</strong>
	</p>
	<p>
	Checking to see if "<%= strFileThatExists %>" exists:
	<b><%= File.Exists(Server.MapPath(strFileThatExists)) %></b>
	</p>
	<p>
	Checking to see if "<%= strFileThatDoesnt %>" exists:
	<b><%= File.Exists(Server.MapPath(strFileThatDoesnt)) %></b>
	</p>
	<p>
	<strong>Function Version:</strong>
	</p>
	<p>
	Checking to see if "<%= strFileThatExists %>" exists:
	<b><asp:Literal id="litFileThatExists" runat="server" /></b>
	</p>
	<p>
	Checking to see if "<%= strFileThatDoesnt %>" exists:
	<b><asp:Literal id="litFileThatDoesnt" runat="server" /></b>
	</p>
</form>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/file_exists_aspx.asp">here</a>
to read about and download the source code.
</p>
</body>
</html>