As per question how to i create a a file that also includes the Byte Order Mark?
Having some trouble displaying some chars because the csv viewer cannot display the chars correctly without the BOM.
Appreciate any help.
EDIT To Include code:
string attachment = string.Format("attachment; filename=results_{0}_to _{1}.csv", startDate.ToString("MM_yy_yyyy"), endDate.ToString("MM_yy_yyyy"));
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
string content = GetTextFromDB();
HttpContext.Current.Response.Write(content);
HttpContext.Current.Response.End();
This should be done automatically for any of the inbuilt code using an
Encoding, such asStreamWriter– just make sure that the encoder you pass in is configured to include a bom (the defaultEncoding.UTF8includes the bom).If you are handling your own
Encoding->Streamlogic, then you need to call.GetPreamble()and write those bytes at the start of the stream.The default
Encoding.UTF8includes the preamble; but you can do it explicitly in the ctor:new UTF8Encoding(true)