1.

How to check if a file exists in C#

Answer»

The File.EXISTS() method is used in C# to check if a file exists or not.

In the parameter, set the name and path of the file you want to check exist or not.

File.Exists(@"C:\One.txt")

The following is an example:

using SYSTEM; using System.IO; class Example {   STATIC void Main() {      if (File.Exists(@"C:\One.txt")) {         Console.WriteLine("File exists!");      } ELSE {         Console.WriteLine("File does not exist!");      }   } }

The output:

File foes not exist!


Discussion

No Comment Found