Answers for "create file if not exists c#"

0

create file if not exists c#

You can simply call

using (StreamWriter w = File.AppendText("log.txt"))
It will create the file if it doesn't exist and open the file for appending.

Edit:

This is sufficient:

string path = txtFilePath.Text;               
using(StreamWriter sw = File.AppendText(path))
{
  foreach (var line in employeeList.Items)                 
  {                    
    Employee e = (Employee)line; // unbox once
    sw.WriteLine(e.FirstName);                     
    sw.WriteLine(e.LastName);                     
    sw.WriteLine(e.JobTitle); 
  }                
}
Posted by: Guest on March-08-2021

Code answers related to "create file if not exists c#"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language