How to find out if a file exists in C# / .NET?

Daren Thomas picture Daren Thomas · Sep 2, 2008 · Viewed 265.2k times · Source

I would like to test a string containing a path to a file for existence of that file (something like the -e test in Perl or the os.path.exists() in Python) in C#.

Answer

Daniel Jennings picture Daniel Jennings · Sep 2, 2008

Use:

File.Exists(path)

MSDN: http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx

Edit: In System.IO