By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,365 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,365 IT Pros & Developers. It's quick & easy.

Response.AddHeader corrupts Japanese/chinese characters when writing outputstrea

P: n/a
Hello. I have this problem. See I have a transformed XML
file and I checked its contents prior to outputting it to
excel file via responseset. here is the gist of the code:

XmlReader reader = myEsiCommand.ExecuteXmlReader();
reader.MoveToContent();
string myCSV = reader.ReadInnerXml();

//Load the xml fragment into the document
XmlDocument xmlDataDoc = new XmlDocument();
xmlDataDoc.LoadXml(myCSV);

//Load the stylesheet to perform the transformation
string path = ConfigurationSettings.AppSettings.Get
("TransformationsPath");
string xslPath = Server.MapPath(path + "/APExport.xsl");
XslTransform transform = new XslTransform();
transform.Load(xslPath);

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);

transform.Transform(xmlDataDoc,null,sw);

Response.ContentType="application/x-msexcel";
Response.Charset = "utf-8";
Response.AddHeader("content-disposition","attachment;
filename=download.csv");
Response.Clear();
Response.Write(sb.ToString());
Response.End();

This code is executed when a user clicks a link to
download a comma separated value (csv) file.

The result of this code is that the string from
StringBuilder "sb" is outputted to an excel file. The
string contains japanese characters and these are then
corrupted/converted into i assume ascii characters.
I tried commenting out Response.AddHeader and tried
writing the output to an ordinary html. the japanese
characters were intact. i also tried inspecting the
stringbuilder data (where the transformed xml was written
to) and the japanese characters were also intact. its only
when i do the Response.AddHeader command that the chars
get jumbled. I do not know of any other way to output this
data as an attachment to an excel file. does anybody have
any ideas? Much thanks in advance!
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
the corrupted Japanese characters appear like this:
ff,,,,,f"(o?)
-----Original Message-----
Hello. I have this problem. See I have a transformed XML
file and I checked its contents prior to outputting it to
excel file via responseset. here is the gist of the code:

XmlReader reader = myEsiCommand.ExecuteXmlReader();
reader.MoveToContent();
string myCSV = reader.ReadInnerXml();

//Load the xml fragment into the document
XmlDocument xmlDataDoc = new XmlDocument();
xmlDataDoc.LoadXml(myCSV);

//Load the stylesheet to perform the transformation
string path = ConfigurationSettings.AppSettings.Get
("TransformationsPath");
string xslPath = Server.MapPath(path + "/APExport.xsl");
XslTransform transform = new XslTransform();
transform.Load(xslPath);

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);

transform.Transform(xmlDataDoc,null,sw);

Response.ContentType="application/x-msexcel";
Response.Charset = "utf-8";
Response.AddHeader("content-disposition","attachment;
filename=download.csv");
Response.Clear();
Response.Write(sb.ToString());
Response.End();

This code is executed when a user clicks a link to
download a comma separated value (csv) file.

The result of this code is that the string from
StringBuilder "sb" is outputted to an excel file. The
string contains japanese characters and these are then
corrupted/converted into i assume ascii characters.
I tried commenting out Response.AddHeader and tried
writing the output to an ordinary html. the japanese
characters were intact. i also tried inspecting the
stringbuilder data (where the transformed xml was written
to) and the japanese characters were also intact. its only when i do the Response.AddHeader command that the chars
get jumbled. I do not know of any other way to output this data as an attachment to an excel file. does anybody have
any ideas? Much thanks in advance!
.

Nov 18 '05 #2

P: n/a
I think you problem is you are using utf-8

Response.Charset = "utf-8";

Try using one of the other ones maybe BigEdian ( I don't remember how it is
spelled ). But that one may work for you because it is used for asian
characters if I remember right.
"Joseph" <is**************@yahoo.com> wrote in message
news:07****************************@phx.gbl...
Hello. I have this problem. See I have a transformed XML
file and I checked its contents prior to outputting it to
excel file via responseset. here is the gist of the code:

XmlReader reader = myEsiCommand.ExecuteXmlReader();
reader.MoveToContent();
string myCSV = reader.ReadInnerXml();

//Load the xml fragment into the document
XmlDocument xmlDataDoc = new XmlDocument();
xmlDataDoc.LoadXml(myCSV);

//Load the stylesheet to perform the transformation
string path = ConfigurationSettings.AppSettings.Get
("TransformationsPath");
string xslPath = Server.MapPath(path + "/APExport.xsl");
XslTransform transform = new XslTransform();
transform.Load(xslPath);

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);

transform.Transform(xmlDataDoc,null,sw);

Response.ContentType="application/x-msexcel";
Response.Charset = "utf-8";
Response.AddHeader("content-disposition","attachment;
filename=download.csv");
Response.Clear();
Response.Write(sb.ToString());
Response.End();

This code is executed when a user clicks a link to
download a comma separated value (csv) file.

The result of this code is that the string from
StringBuilder "sb" is outputted to an excel file. The
string contains japanese characters and these are then
corrupted/converted into i assume ascii characters.
I tried commenting out Response.AddHeader and tried
writing the output to an ordinary html. the japanese
characters were intact. i also tried inspecting the
stringbuilder data (where the transformed xml was written
to) and the japanese characters were also intact. its only
when i do the Response.AddHeader command that the chars
get jumbled. I do not know of any other way to output this
data as an attachment to an excel file. does anybody have
any ideas? Much thanks in advance!

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.