Tuesday 8 July 2014

.NET | Issue | CSV export giving corrupted chars for non english characters Â

Someone asked me today about an encoding problem they were having, its amazing, encoding issues have been around since the beginning of computers, the requirement to export international data to files or pages and having the reader interpret the characters correctly is pretty common, I would go so far as to say that about half of every big projects has some form of requirement around that.

So then we come to why the issue shows up? "Ive debugged and can see the data from the database is being shown correctly but when i export it to the response, the special characters come back as gobbledygook, even the pound symbol is coming back as '£'"

what do you do?

  1. Check the data in the database is stored correctly and it is getting to the response without being corrupted
  2. Check you are setting the ContentEncoding correctly, what do you need to use? UTF8 is always a good one to use if you are unsure
  3. Make sure you are using the right BOM (Byte Order Mark)! (this is nearly always the issue with unexplained chars with the correct encoding, see below

if you want to know more about BOM, have a look at this - http://en.wikipedia.org/wiki/Byte_order_mark

No comments:

Post a Comment