News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

See if a file exists in VB .NET

Started by nandagopal, Nov 17, 2008, 07:29 PM

Previous topic - Next topic

nandagopal

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