ASP.NET DataGrid – Export to CSV encoding issue

If you are exporting an asp.net grid to the CSV format you might see some special characters appearing the exported file. This is because of not setting the right encoding format. I initially tried with UTF8, UTF32 and Unicode and none of them exported the data correctly. Finally I set the encoding to default like this –

Response.ContentEncoding = Encoding.Default;

Finally the single quotes and hypens were appearing correctly in the CSV. Please not that you have to HtmlDecode your data if you have already HtmlEncoded it.

Advertisements