title: Create File If File Does Not Exist
body: <p>I need to get my code to read if file doesnt exist create else append. Right now it is reading if it does exist create and append. Here is the code:</p>
  
  <pre><code>if (File.Exists(path))
  {
      using (StreamWriter sw = File.CreateText(path))
      {
  </code></pre>
  
  <p>Would I do this?</p>
  
  <pre><code>if (! File.Exists(path))
  {
      using (StreamWriter sw = File.CreateText(path))
      {
  </code></pre>
  
  <p>Edit:</p>
  
  <pre><code>string path = txtFilePath.Text;
  
  if (!File.Exists(path))
  {
      using (StreamWriter sw = File.CreateText(path))
      {
          foreach (var line in employeeList.Items)
          {
              sw.WriteLine(((Employee)line).FirstName);
              sw.WriteLine(((Employee)line).LastName);
              sw.WriteLine(((Employee)line).JobTitle);
          }
      }
  }
  else
  {
      StreamWriter sw = File.AppendText(path);
  
      foreach (var line in employeeList.Items)
      {
          sw.WriteLine(((Employee)line).FirstName);
          sw.WriteLine(((Employee)line).LastName);
          sw.WriteLine(((Employee)line).JobTitle);
      }
      sw.Close();
  }
  </code></pre>
  
  <p>}</p>