Answers for "create text file if it does not exist and write line c#"

C#
0

c# create file if not exists

string rootPath = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
        rootPath += "MTN";
        if (!(File.Exists(rootPath)))
        {
            File.CreateText(rootPath);
        }
Posted by: Guest on October-15-2021
0

c# if file doesn't exist create it

string temp = AppDomain.CurrentDomain.BaseDirectory;
string sPath = Path.Combine(temp, "file.txt");

bool fileExist = File.Exists(sPath);
        if (fileExist) {
            Console.WriteLine("File exists.");
        }
        else {
          using (File.Create(sPath)) ;
            Console.WriteLine("File does not exist.");
        }
Posted by: Guest on September-18-2021

Code answers related to "create text file if it does not exist and write line c#"

C# Answers by Framework

Browse Popular Code Answers by Language