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: 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 3: C# Create new file

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