FileSystem.FileExists Method (String)
.NET Framework (current version)
![]() |
---|
The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience. |
Returns True if the specified file exists.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
Parameters
- file
-
Type:
System.String
Name and path of the file.
Return Value
Type: System.BooleanReturns True if the file exists; otherwise this method returns False.
Exception | Condition |
---|---|
ArgumentException | The name of the file ends with a backslash (\). |
If the application does not have sufficient permissions to read the specified file, the FileExists method returns False, regardless of the existence of the path; the method does not throw an exception.
This example checks to see whether or not the file Check.txt exists and supplies the information in a message box.
If My.Computer.FileSystem.FileExists("c:\Check.txt") Then MsgBox("File found.") Else MsgBox("File not found.") End If
FileIOPermission
Controls the ability to access files and folders. Associated enumeration: Unrestricted.
.NET Framework
Available since 2.0
Available since 2.0
Show: