Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

io

People also ask

How do you know if a file is a directory in C?

The isDir() function is used to check a given file is a directory or not.

How do I check if a file is present in C++?

Use ifile. open(): ifile. open() is mainly used to check if a file exists in the specific directory or not.

What is the condition to check whether file exist or not?

While checking if a file exists, the most commonly used file operators are -e and -f. The '-e' option is used to check whether a file exists regardless of the type, while the '-f' option is used to return true value only if the file is a regular file (not a directory or a device).


Use:

File.Exists(path)

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

Edit: In System.IO


System.IO.File:

using System.IO;

if (File.Exists(path)) 
{
    Console.WriteLine("file exists");
} 

System.IO.File.Exists(path)

msdn


Give full path as input. Avoid relative paths.

 return File.Exists(FinalPath);