Solved

c# File System method - FileExists()

Posted on 2008-06-26
3
790 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:Daniel Reynolds
ID: 21876512
try the following
using System.IO;

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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hey!! 5 33
C# bracket error 3 30
Getting error in connectionstring with Excel. 30 30
transaction in asp.net, sql server 6 31
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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