file create c# code example

Example 1: how to create a file in c#

// File class is in the System.IO namespace
FileStream file = File.Create(path);
file.Close()

Example 2: how to create empty text file in c#

using (File.Create(filename)) ;

Example 3: create a file in the directory of the exe and write to it c#

string GuarnteedWritePath = System.Environment.
                             GetFolderPath(
                                 Environment.SpecialFolder.CommonApplicationData
                             );
            string FilePath = Path.Combine(GuarnteedWritePath, "LogFile.txt");

Example 4: C# Create new file

public static System.IO.FileStream Create (string path);