www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to check whether a filie is existing

  1. #1
    Join Date
    Jul 2003
    Posts
    69

    How to check whether a filie is existing

    Well I am tying to open a file for reading which does not exist and thus getting an erro message. How to check whether a file is existing before I open it for reading?

    I am using VB.NET and doing windows application

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    Well what I would probably do is create a data set with all the files in the directory in it, then check the file name string with the data set. There is probably a more efficient way, but this could make it easier for you if you want to use other information about the file or several files. I can probably post code on how to populate a data set with file info or read from a directory.

  3. #3
    Join Date
    Nov 2004
    Location
    Utah
    Posts
    23
    You should use the System.IO.File class. It has a shared method called Exists.

    Code:
    Imports System.IO
    
    ' then in the function
    
    If File.Exists(filepath) Then
      'open it
    Else
      'dont open it.
    End If
    HTH.

    Ben Miller

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles