title: Export unicode data to CSV file
body: <p>Though this question is asked several times by many people, but again I cannot generate the required CSV file in a proper text. I am creating a CSV file which characters are set in Japanese language. Whenever I generate a CSV file, it is not exporting it in proper encoding. I want it to make it readable in a excel sheet. It is showing correct data while debugging and also notepad is displaying correct csv but while when I read the file from Excel, all text get messed up.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void GenerateCSV(string[][] value)
      {
          string attachment = "attachment; filename=CreatedCSV.csv";
  
          HttpContext.Current.Response.Clear();
          HttpContext.Current.Response.ClearHeaders();
          HttpContext.Current.Response.ClearContent();
          HttpContext.Current.Response.AddHeader("content-disposition", attachment);
          HttpContext.Current.Response.ContentType = "text/csv";
          HttpContext.Current.Response.Charset = "";
          HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
          HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
  
          string delimiter = ", ";
          int length = value.GetLength(0);
          StringBuilder sb = new StringBuilder();
          for (int index = 0; index &lt; length; index++)
              sb.AppendLine(string.Join(delimiter, value[index]));
  
          HttpContext.Current.Response.Write(sb.ToString());
          HttpContext.Current.Response.End();
      }
  </code></pre>
  
  <p>I tried implementing unicode too but it also did not help. What am I missing here?</p>
  
  <p>Excel file looks like this:
  <a href="https://i.stack.imgur.com/iymoj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iymoj.jpg" alt="enter image description here"></a></p>
  
  <p>While the notepad displays data correctly as below:
  <a href="https://i.stack.imgur.com/aSUHz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aSUHz.jpg" alt="enter image description here"></a></p>