title: c#, Excel + csv: how to get the correct encoding?
body: <p>I've been trying this for quite a while now, but can't figure it out.  I'm trying to export data to Excel via a *.csv file.  It works great so far, but I have some encoding problems when opening the files in Excel.</p>
  
  <p>(original string on the left, EXCEL result on the right): </p>
  
  <pre><code>Messwert(µm / m) ==&gt; Messwert(Âµm / m)
  
  Dümme Mässöng ==&gt; DÃ¼mme MÃ¤ssÃ¶ng
  </code></pre>
  
  <p>Notepad++ tells me that the file is encoded "ANSI as UTF8"(WTF?) </p>
  
  <p>So here are different ways I tried to get a valid result: 
  obvious implementation: </p>
  
  <pre><code>tWriter.Write(";Messwert(µm /m)");
  </code></pre>
  
  <p>more sophisticated one (tried probably a dozen or more encoding combinations:)</p>
  
  <pre><code>tWriter.Write(Encoding.Default.GetString(Encoding.Unicode.GetBytes(";Messwert(µm /m)")));
  tWriter.Write(Encoding.ASCII.GetString(Encoding.Unicode.GetBytes(";Messwert(µm /m)")));
  </code></pre>
  
  <p>and so on</p>
  
  <p>Whole source code for the method creating the data:</p>
  
  <pre><code>    MemoryStream tStream = new MemoryStream();
      StreamWriter tWriter = new StreamWriter(tStream);
      tWriter.Write("\uFEFF");
  
      tWriter.WriteLine(string.Format("{0}", aMeasurement.Name));
      tWriter.WriteLine(aMeasurement.Comment);
      tWriter.WriteLine();
      tWriter.WriteLine("Zeit in Minuten;Messwert(µm / m)");
  
      TimeSpan tSpan;
      foreach (IMeasuringPoint tPoint in aMeasurement)
      {
          tSpan = new TimeSpan(tPoint.Time - aMeasurement[0].Time);
          tWriter.WriteLine(string.Format("{0};{1};", (int)tSpan.TotalMinutes, getMPString(tPoint)));
      }
  
      tWriter.Flush();
      return tStream;
  </code></pre>
  
  <p>Generated CSV file:</p>
  
  <pre><code>Dümme Mössäng
  Testmessung die erste
  
  Zeit in Minuten;Messwert(µm / m)
  0;-703;
  0;-381;
  1;1039;
  1;1045;
  2;1457;
  2;1045;
  </code></pre>