Solved

c# File System method - FileExists()

Posted on 2008-06-26
3
787 Views
Last Modified: 2011-04-14
Greetings:

I'm hoping to get code and supporting namespace that will execute the following routine:

FileExits()

For example:

using ??

void CheckFile()
{
...                      // necessary variables like 'string FilePath'
FileExists()        // correct call
return;
}

Thanks
0
Comment
Question by:John500
3 Comments
 
LVL 19

Expert Comment

by:elimesika
ID: 21876452
see code



using System.IO;
 

string path = @"c:\a.txt";
 

if (File.Exists(path)) {

// do something

}

Open in new window

0
 
LVL 10

Accepted Solution

by:
oxyoo earned 500 total points
ID: 21876461
Hi,

See the code below. You call the method like this:

bool fileExists = FileTools.CheckFile(@"c:\tmp2.xml");

Good Luck!

using System.IO;
 

namespace MyProjects {

    public class FileTools {
 

        public static bool CheckFile(string filename) {

            return File.Exists(filename) ? true : false;

        }
 

    }

}

Open in new window

0
 
LVL 17

Expert Comment

by:xDJR1875
ID: 21876512
try the following
using System.IO;

System.IO.File.Exists("myfilepath\andname")
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

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

13 Experts available now in Live!

Get 1:1 Help Now