Solved

c# File System method - FileExists()

Posted on 2008-06-26
3
789 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Image(7) 1 53
Name space syntax error 12 39
Server Error 11 47
SQL Login 17 38
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 was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

919 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

12 Experts available now in Live!

Get 1:1 Help Now