0

I am developing a website that allow to export data in MSSQL to a CSV file but i have a trouble that my Data Base contain Vietnamese so when i export it to CVS file. All of Vietnamese has error! How could i do to export Vietnamese without error with Vietnamese data? Here my return file code:

return File(new System.Text.UnicodeEncoding().GetBytes(str.ToString()), "text/csv", filename + DateTime.Now + ".csv");
Ognyan Dimitrov
  • 6,026
  • 1
  • 48
  • 70
  • look here: http://stackoverflow.com/questions/1679656/asp-net-excel-export-encoding-problem and: http://stackoverflow.com/questions/31024776/export-different-language-content-in-csv-file-in-c-sharp – DasDas Jul 01 '15 at 14:04

2 Answers2

0

Have you tried with CultureInfo class? Like this:

return File(new System.Text.UnicodeEncoding().GetBytes(str.ToString( new CultureInfo("vi"))), "text/csv", filename + DateTime.Now + ".csv");
Ognyan Dimitrov
  • 6,026
  • 1
  • 48
  • 70
0

It worked.

Response.ContentEncoding = System.Text.Encoding.Unicode; Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());