|
|
Title | See if a file exists in VB .NET |
Description | This example shows how to see if a file exists in Visual Basic .NET. |
Keywords | file exists, file, exists |
Categories | VB.NET, Files and Directories |
|
|
The System.IO.File.Exists method returns True if a file exists.
|
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Dim file_path As String = Application.StartupPath
file_path = file_path.Substring(0, _
file_path.LastIndexOf("\"))
If System.IO.File.Exists(file_path & "\Form1.vb") Then
lblFile1.Text = "Form1.vb exists"
Else
lblFile1.Text = "Form1.vb does not exist"
End If
If System.IO.File.Exists(file_path & "\Missing.vb") Then
lblFile2.Text = "Missing.vb exists"
Else
lblFile2.Text = "Missing.vb does not exist"
End If
End Sub
|
|
There's lots more information about VB 2005 in my book Visual Basic 2005 Programmer's Reference.
|
|
|
|
|
|