Solved

Checking for the existence of a File

Posted on 2006-11-21
4
169 Views
Last Modified: 2010-04-30
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.  
0
Comment
Question by:VBStudent
  • 2
4 Comments
 
LVL 11

Expert Comment

by:ch2
ID: 17990651
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
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17990672
For VB.Net 2005, use the new "My" namespace:

        If My.Computer.FileSystem.FileExists("c:\someFile.txt") Then

        Else

        End If
0
 

Author Comment

by:VBStudent
ID: 17990737
That was a slick solution. Thank you for your quick response
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17990805
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...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 65
Child Form in front 4 49
Dinamic report to Crosstab query 9 33
Collapse and expand table in Word 2010 2 32
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question