ASP to ASP.NET: File exists

31. December 2006 07:30 by Mrojas in General  //  Tags:   //   Comments (0)


This is the migration of a snippet of ASP classic to ASP.Net

 

Checking that a File Exists ASP Classic

<%
Dim strExists  
Dim strNotExists 
Dim objFileSystemObjectVar
``
strExists    = "exists.txt"
strNotExists = "error.txt"
 
Set objFileSystemObjectVar = Server.CreateObject("Scripting.FileSystemObject")
 
' The FileExists method expects a fully qualified path and
' use Server.MapPath 
%>
<p>
&quot;<%= strExists %>&quot; exists:
<b><%=objFileSystemObjectVar.FileExists(Server.MapPath(strExists)) %></b>
</p>
<p>
&quot;<%= strNotExists %>&quot; exists:
<b><%= objFileSystemObjectVar.FileExists(Server.MapPath(strNotExists)) %></b>
</p>

 

Checking that a file exists ASP.NET

 

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
        Dim strExists As String = "exists.txt"
        Dim strNotExists As String = "error.txt"
</script>
<p>
&quot;<%= strExists %>&quot; exists:
<b><%=File.Exists(Server.MapPath(strExists))%></b>
</p>
<p>
&quot;<%= strNotExists %>&quot; exists:
<b><%= File.Exists(Server.MapPath(strNotExists))%></b>
</p>