C # context.Response.OutputStream.Write Hebrew characters

I am trying to export a report to csv using this code:

byte[] csvBytes = AttachmentFileAgent.GetAttachmentFilesCSVBytes(context.Request["appCode"], performingPerson);
context.Response.AddHeader("content-disposition", "attachment; filename=ApplicationReport_" + context.Request["appCode"] + ".csv");
context.Response.ContentType = "text/csv;charset=utf-8";
context.Response.Charset = "utf-8";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.OutputStream.Write(csvBytes, 0, csvBytes.Length);

But the Hebrew content goes into gibberish ('>' ¢ '>' '¢'> ''> '¢). I tried to use all kinds of coding (UTF8, Unicode, ASCII), but nothing works ...

+4
source share
1 answer

Your changes to the context.Response.ContentEncodingencoding TextWriterused bycontext.Response.Output

When using, context.Response.OutputStreamyou need to set the UTF-8 encoding used in your function GetAttachmentFilesCSVBytes.

Also see ASP.NET: will XmlDocument be stored in Response.OutputStream read encoding?

0
source

All Articles