csharp if file doesn't exist create it

Code Example - csharp 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.");
        }
                    
                
 

csharp create file if not exists

                        
                                string rootPath = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
        rootPath += "MTN";
        if (!(File.Exists(rootPath)))
        {
            File.CreateText(rootPath);
        }