Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

c# File System method - FileExists()

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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