Link to home
Start Free TrialLog in
Avatar of VBStudent
VBStudent

asked on

Checking for the existence of a File

Hi, I am using Visual Basic 2005.  I am trying to check for the existence of a file.  Apparently, I am not importing the correct libraries because FileExists is not recognized.  Any suggestions of syntax would be appreciated.  
Avatar of ch2
ch2

Hi
 Try this

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Path As String
        Try
            Path = "yourfilepath"
            If IO.File.Exists(Path) Then
                MsgBox("File exists")
            Else
                MsgBox("File dosen't exists")
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

ch2
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBStudent

ASKER

That was a slick solution. Thank you for your quick response
Um...thanx.

Though it really isn't any better/worse than ch2's submission.

It just uses a different namespace...

There are LOTS of goodies in the "My" namespace though.

My.Application:
http://msdn2.microsoft.com/en-us/library/ms172938.aspx

My.Application.OpenForms:
http://msdn2.microsoft.com/en-us/library/eh13dca9.aspx

My.Computer:
http://msdn2.microsoft.com/en-us/library/ms172948.aspx

and lots of other stuff...