Wednesday, 21 August 2013

C# Unable to print euro symbol into a file

C# Unable to print euro symbol into a file

I have a problem with a get method into a web api controller. This method
returns a HttpResponseMessage object which has a HttpContent with a csv
file, which contains euro symbols. When the method returns the file, the
euro symbol isn't printed. The code of the method is the following:
string export = ... //string with fields separed by ';' and with euro symbol
HttpResponseMessage response = new HttpResponseMessage();
UTF8Encoding encoding = new UTF8Encoding();
Byte[] buffer = encoding.GetBytes(export);
response.Content = new ByteArrayContent(buffer);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv");
response.Content.Headers.ContentDisposition = new
ContentDispositionHeaderValue("attachment") { FileName = "Export.csv" };
response.Content.Headers.ContentLength = export.Length;
response.Content.Headers.Expires = new
DateTimeOffset(DateTime.Now.AddDays(1));
return response;
When I open the file, the euro symbol doesn't appear correctly. Could you
give me an answer?
Thanks a lot.

No comments:

Post a Comment