473,324 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 3670
the corrupted Japanese characters appear like this:
ãf¯ãf³ã,¢ã,½ã,·ã,¨ã,¤ã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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim E. | last post by:
Using VC++ on an application for English Win 95/98 thru XP, how can I display multi-byte characters (Asian languages or roman characters with accent marks) in standard MFC controls like CEdit,...
1
by: GPenn | last post by:
SQL 2000, latest SP. We currently have the need to store data from a UTF-8 application in multiple languages in a single database. Our findings thus far support the fact that single-byte and...
1
by: Sven Hanefeld | last post by:
Hi, who is able to help. I want to translate my whole website into japanese language. www.nord-com.net/hanefeld What do I have to do except finding a japanese guy for the translation. Do I...
12
by: paulgor | last post by:
Hi, May be it's a know issue but my search brought nothing... We have static HTML files with Japanese text in UTF-8 encoding - it's on-line Help for our application, so there are no Web...
6
by: john | last post by:
The standard method to transmit a file from an aspx page to a browser is to stream the file to the response then end the response. The HTML code generated by the aspx page is discarded, and the...
4
by: wheel | last post by:
I have already built in support for multiple languages in some of my applications, but so far they have only used Western languages (English, Spanish, etc). I need to add some Far East languages:...
2
by: Clive Green | last post by:
Hello peeps, I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and writing MP3 tags). I have been using PHP on the command line (Mac OS X Unix shell, to be precise), and am...
12
by: Steve Howell | last post by:
The never-ending debate about PEP 3131 got me thinking about natural languages with respect to Python, and I have a bunch of mostly simple observations (some factual, some anecdotal). I present...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.