[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 801
  • Last Modified:

c# File System method - FileExists()

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
John500
Asked:
John500
1 Solution
 
elimesikaCommented:
see code



using System.IO;
 
string path = @"c:\a.txt";
 
if (File.Exists(path)) {
// do something
}

Open in new window

0
 
oxyooCommented:
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
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
try the following
using System.IO;

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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now