This example shows you How to use File Class to Create or Check file exists in C#. The File class providers static methods for creating, opening, writing, deleting...etc.

How to create a File in C#

To create a file you can use the Create method of the File class.

string fileName = @"c:\\dotnet.txt";
File.Create(fileName);

How to check a File exist or not in C#

If you want to check a file exists or not you can use the Exists method of the File class.

string fileName = @"c:\\test.txt"
if(File.Exists(fileName)){
   //do something
}

Before creating the file, you should check whether the file exists, then create the file.