Check if a File Exists in C#

The Exists method checks if the specified file exists. The following code snippet checks if a file exists or not.

string fileName = @"c:\temp\Mahesh.txt";
if
(File.Exists(fileName))
    Console.WriteLine("File exists.");
else

    Console.WriteLine("File does not exist.");

Up Next
    Ebook Download
    View all
    Learn
    View all