Articles  
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Search Directory
ASP Directory
Xml Directory

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to Check if a file exists using FileSystemObject

Author: Asif

In many cases we need to check if a particular file exists on the server or not. This simple function returns true or false based on the file existence. Just pass a valid file name to the function.

<%
Option Explicit

Dim FileName

FileName = "MyFile.asp"
FileName = Server.MapPath("/Files/" & FileName)

If IsFileExists(FileName) = True  Then
 Response.Write "File exists"
Else
 Response.Write "File does not exists"
End If


' **********************************
' Function to check file Existance
' **********************************
Function IsFileExists(byVal FileName)
 
 If FileName = ""  Then
  IsFileExists = False
  Exit Function
 End If
 
 Dim objFSO
    
 Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    
 If (objFSO.FileExists( FileName ) = True  Then
  IsFileExists = True
 Else
  IsFileExists = False
 End If
  
 Set objFSO = Nothing   
End Function
%>
Disclaimer - Privacy
© 2002-2012 DevASP.com