469,609 Members | 1,657 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Response.AddHeader corrupts Japanese/chinese characters when writing outputstrea

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
2 3503
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
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.

Similar topics

1 post views Thread by Sven Hanefeld | last post: by
12 posts views Thread by paulgor | last post: by
6 posts views Thread by john | last post: by
12 posts views Thread by Steve Howell | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.