Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSee if a file exists in VB .NET
DescriptionThis example shows how to see if a file exists in Visual Basic .NET.
Keywordsfile exists, file, exists
CategoriesVB.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.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated