title: C# FileStream StreamWriter another process exception
body: <p>I'm writing a CSV file from a <code>DataGridView</code>.
  When I open the file during the process (while the task is writing to the file) I get an error because:</p>
  
  <p><code>The process cannot access the file 'xyz\filename.csv' because it is being used by another process.</code> </p>
  
  <p>I've tried  manually calling the <code>Flush()</code> method on both <code>file</code> and <code>swOut</code> after each write but I still get the error.</p>
  
  <p>I need to use <code>FileMode.Append</code> because after file is created I add n-rows. I've tried each of the different options for the <code>FileShare</code> enumeration, but nothing is working.</p>
  
  <p>Where am I wrong?</p>
  
  <p>My code:</p>
  
  <pre><code>using (FileStream file = new FileStream(output_file, FileMode.Append, FileAccess.Write, FileShare.Read))
  {
      StreamWriter swOut = new StreamWriter(file);
      swOut.AutoFlush = true;
      if (table.Rows.Count == 2)
      {
          for (int i = 0; i &lt;= table.Columns.Count - 1; i++)
          {
              if (i &gt; 0)
              {
                  swOut.Write(",");
              }
              swOut.Write(table.Columns[i].HeaderText);
          }
          swOut.WriteLine();
      }
      swOut.Write(category.Replace(",", " ") + "," + name.Replace(",", " ") + "," + address.Replace(",", " ") + "," + locality.Replace(",", " ") + "," + cap.Replace(",", " ") + "," + tel.Replace(",", " ") + "," + fax.Replace(",", " ") + "," + www.Replace(",", " ") + "," + email_results.Replace(",", " ") + "," + business_url.Replace(",", " ") + "," + map_query.Replace(",", " "));
      swOut.WriteLine();
      file.Close();
      if (stop == true) output_file = "";
  }
  </code></pre>