Solved

Checking for the existence of a File

Posted on 2006-11-21
4
166 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now