title: File being used by another process after using File.Create()
body: <p>I'm trying to detect if a file exists at runtime, if not, create it. However I'm getting this error when I try to write to it: </p>
  
  <blockquote>
    <p>The process cannot access the file 'myfile.ext' because it is being used by another process.</p>
  </blockquote>
  
  <pre><code>string filePath = string.Format(@"{0}\M{1}.dat", ConfigurationManager.AppSettings["DirectoryPath"], costCentre); 
  if (!File.Exists(filePath)) 
  { 
      File.Create(filePath); 
  } 
  
  using (StreamWriter sw = File.AppendText(filePath)) 
  { 
      //write my text 
  }
  </code></pre>
  
  <p>Any ideas on how to fix it?</p>