i am writing text to a TextWriter
. i want the UTF-16 Byte Order Mark (BOM
) to appear in the output:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentEncoding = new UnicodeEncoding(true, true);
WriteStuffToTextWriter(context.Response.Output);
}
Except the output doesn't contain a byte order mark:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 06 Sep 2012 21:09:23 GMT
X-AspNet-Version: 4.0.30319
Content-Disposition: attachment; filename="Transactions_Calendar_20120906.csv"
Cache-Control: private
Content-Type: text/csv; filename="Transactions_Calendar_20120906.csv"; charset=utf-16BE
Content-Length: 95022
Connection: Close
JobName,ShiftName,6////09////2012 12::::00::::00 АΜ,...
How do i tell a TextWriter
to write the encoding marker?
Note: The 2nd paramter in UnicodeEncoding
:
context.Response.ContentEncoding = new UnicodeEncoding(true, true);
byteOrderMark
Type:System.Boolean
true to specify that a Unicode byte order mark is provided; otherwise, false.
WriteStuffToTextWriter
you probably have to specify the encoding there in yourStreamWriter
– Washedout