Solved

c# File System method - FileExists()

Posted on 2008-06-26
3
794 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
[X]
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
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

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