title: How to make sure my created filedownload is UTF-8? (and not UTF-8 without BOM)
body: <p>i've made a download function to download messages to a CSV file (code is below).
  Now when i open it up in notepad or notepad++ i see this:</p>
  
  <p>é NY ø ╬ ║► ░ ê ö </p>
  
  <p>(and that is what is in the database btw)</p>
  
  <p>Now, when i open it up in Ms-Excel it shows this:</p>
  
  <p>Ã© NY Ã¸ â•¬ â•‘â–º â–‘ Ãª Ã¶ </p>
  
  <p>When i open it up in notepad++, it says it's encoded in 'UTF8 without BOM'.
  When i encode it (in notepad++) to UTF-8, all goes well (that is, Excel shows the right chars too)</p>
  
  <p><strong>But how can i make sure that the file i create from my code is UTF-8?</strong></p>
  
  <p>This is my code:</p>
  
  <pre><code>public ActionResult DownloadPersonalMessages()
  {    
      StringBuilder myCsv = new StringBuilder();
      myCsv.Append(new DownloadService().GetPersonalMessages());
  
      this.Response.ContentType = "text/csv";
      Response.AddHeader("content-disposition", "attachment; filename=PersonalMessages.csv");
      Response.ContentEncoding = Encoding.UTF8;
      Response.Write(myCsv.ToString());
      Response.Flush();
      Response.HeaderEncoding = Encoding.UTF8;
      return Content("");
  }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>my function now returns a <code>ByteArray</code> with this conversion</p>
  
  <pre><code>UTF8Encoding encoding = new UTF8Encoding();
  return encoding.GetBytes(str);
  </code></pre>
  
  <p>and my download is now this:</p>
  
  <pre><code>Response.AddHeader("Content-Disposition", "attachment; filename=PersonalMessages.csv");
  return File(new DownloadService().GetPersonalMessages(), "text/csv");
  </code></pre>