Check if a File exists in C#
To check whether a file exist in C# we can use the methodFile.exists
, it will return true if file exist and false if not.Remember to include:
using System.IO
using System;
using System.IO;
public class Example
{
public static void Main()
{
if (File.Exists(@"C:\File_Name.txt")) {
Console.WriteLine("File exists...");
} else {
Console.WriteLine("File does not exist!");
}
}
}