I'm exporting a table of data to CSV format, e.g.:
"1","some text", "£232.00"
"2","some more text", "£111.00"
"3","other text", "£2.00"
context.Response.ContentType = "text/csv"
You need to set the encoding i.e. the
After finally looking this up in Reflector, the default
ContentEncoding is likely to be
Encoding.UTF8, if a
system.web/globalization config section exists, unless it is overridden by a
responseEncoding property in that config section.
As to whether setting the
ContentEncoding property at all performs differently to not doing so:
HttpWriter.UpdateResponseEncoding, which calls
HttpWriter.FlushCharBufferbefore switching to the new encoding if there's anything buffered to write already.
ContentEncodingit is set to the default I mentioned above by first reference to
HttpWriter.UpdateResponseEncoding, which is definitely called before any content is written because
HttpWriter._responseEncodingUpdatedis checked in the writing methods and only updated to
Trueat the end of
As such, I believe the OP needed to change the encoding to
Unicode and I assume Phil Hale's comment means he had a
system.web/globalization config section that needed overriding.
Response.Clearonly affects content, not headers, so, contrary to my previous suggestion, I don't believe it is relevant, other than removing any chance of existing content to be present to be flushed before the
System.Webfrom .NET Framework 2.0.