c# - Setting the charset of html response content to 1252 -


i'm trying send data encoded in windows 1252 (it's csv file) in http response, somewhere along way it's getting re-encoded utf-8 (no bom). how can make sure data stays in correct encoding?

var sb = new stringbuilder(); // build file windows-1252 strings in sb... httpcontext.current.response.clear(); httpcontext.current.response.clearheaders(); httpcontext.current.response.clearcontent(); httpcontext.current.response.addheader("content-disposition", string.format("filename=\"{0}\".csv", filename)); httpcontext.current.response.contenttype = "text/csv;charset=windows-1252"; httpcontext.current.response.charset = "windows-1252"; httpcontext.current.response.write(sb.tostring()); httpcontext.current.response.flush(); httpcontext.current.response.end(); 

when call

httpcontext.current.response.write(somestring) 

the input somestring in .net's internal string representation (actually utf-16). send output has converted. default conversion utf-8 (because efficiently supports whole of unicode).

the charset property sets http response headers. not there contentencoding property control how strings sent.

so missing

httpcontext.current.response.contentencoding = encoding.getencoding("windows-1252") 

see description of system.text.encoding list of supported encodings.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -