473,385 Members | 2,028 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,385 software developers and data experts.

encoding problems (utf-8)

I have a problem with utf-8 enconding and I don't know
what to do in order to make it work.

I want to open a new window with excel data so the user
can choose to save it local. Everything works fine, the
new window, the excel data appears, but, extended
characters are wrong.

I call the window from an aspx page using this:

<script language='javascript'> window.open
('excelviewer.aspx?nif=...&id=.....

then, excelviewer.aspx.cs has this:

private void showExcel (DataSet ds) {
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-
Disposition", "inline;filename=consulta.csv");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "utf-8";
//Response.AppendHeader("Content-Transfer-Encoding",
Response.ContentEncoding.EncodingName);
System.Globalization.CultureInfo culture = new
System.Globalization.CultureInfo("es");

System.IO.StringWriter sw = new System.IO.StringWriter
(culture);
HtmlTextWriter htmlw = new HtmlTextWriter(sw);
htmlw.AddAttribute
(HtmlTextWriterAttribute.Title, "Consulta");

DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htmlw);

Response.Write(htmlw.InnerWriter);
Response.Flush();
Response.Close();
}

That is the C# code, it works fine, the new window
appears with the excel content and the correct columns
and rows, but several extended characters appears badly.
I saw on IE view and there is no AutoSelect and UTF-8 is
selected instead.

Also on the aspx I put this <%@ Page language="c#"
ResponseEncoding="UTF-8" Codebehind="excelviewer.aspx.cs"
AutoEventWireup="false"
Inherits="ROCAMP.Formularis.excelviewer" %> but nothing.

Here you can find some explample of the output, it is
just a part of the columns, and only the first line:

NIF NOM ESTAT CARNET NÃsMERO MOVIMENT BORSA DATA
INICI
38112294Y David Bernal Manero Finalitzat BÃ?SIC
BA100000/03 Expedició No 21/01/2004

it should look like this:

NIF NOM ESTAT CARNET NÚMERO MOVIMENT BORSA DATA
INICI
38112294Y David Bernal Manero Finalitzat BÀSIC
BA100000/03 Expedició No 21/01/2004


If anyone could give me some advice, I'll appreciate it
very much.

thanx in advance,

Guillermo.

Nov 18 '05 #1
2 3251
Yes, utf-8 must work fine for me, I used previously in
xsl trasformations and it was fine (without utf-8 the xsl
transformation was unsuccesful), that's why I tried to
put it everywher, because I thought in somewhere the data
changed. I found that the problem is in the writer, I
mean, the data is ok just before writing, I check it
using watches at debugging.

I also tried another way later. Create a phisical csv
file (previously done on another application with utf-8
too, and works fine), and the same happened: in
StreamWriter.WriteLine(data), data is perfectly fine (as
appears in a debuger watch) but after the WriteLine,
opening the csv file shows some characters badly.

So, I don't think it is because of using utf-8. Anyway
I'll try with others codes. Thanx.
-----Original Message-----
Hi
utf-8 is selected because you say so all over your code! (well, even if you didn't it's default anyway.)change the page *and* request/response encoding from utf- 8 to your *local language encoding*.modify the "globalization" section of the web.config file appropriately to have it fixed once and for all.
dimitris

"Guillermo Rosich Capablanca" wrote:
I have a problem with utf-8 enconding and I don't know
what to do in order to make it work.

I want to open a new window with excel data so the user can choose to save it local. Everything works fine, the new window, the excel data appears, but, extended
characters are wrong.

I call the window from an aspx page using this:

<script language='javascript'> window.open
('excelviewer.aspx?nif=...&id=.....

then, excelviewer.aspx.cs has this:

private void showExcel (DataSet ds) {
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-
Disposition", "inline;filename=consulta.csv");
Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Charset = "utf-8";
//Response.AppendHeader("Content-Transfer- Encoding", Response.ContentEncoding.EncodingName);
System.Globalization.CultureInfo culture = new
System.Globalization.CultureInfo("es");

System.IO.StringWriter sw = new System.IO.StringWriter (culture);
HtmlTextWriter htmlw = new HtmlTextWriter(sw);
htmlw.AddAttribute
(HtmlTextWriterAttribute.Title, "Consulta");

DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htmlw);

Response.Write(htmlw.InnerWriter);
Response.Flush();
Response.Close();
}

That is the C# code, it works fine, the new window
appears with the excel content and the correct columns
and rows, but several extended characters appears badly. I saw on IE view and there is no AutoSelect and UTF-8 is selected instead.

Also on the aspx I put this <%@ Page language="c#"
ResponseEncoding="UTF-8" Codebehind="excelviewer.aspx.cs" AutoEventWireup="false"
Inherits="ROCAMP.Formularis.excelviewer" %> but nothing.
Here you can find some explample of the output, it is
just a part of the columns, and only the first line:

NIF NOM ESTAT CARNET NÃfsMERO MOVIMENT BORSA DATA INICI
38112294Y David Bernal Manero Finalitzat BÃf?SIC
BA100000/03 ExpediciÃf³ No 21/01/2004

it should look like this:

NIF NOM ESTAT CARNET NÃsMERO MOVIMENT BORSA DATA INICI
38112294Y David Bernal Manero Finalitzat BÃ?SIC
BA100000/03 Expedició No 21/01/2004


If anyone could give me some advice, I'll appreciate it very much.

thanx in advance,

Guillermo.


.

Nov 18 '05 #2
Guillermo Rosich Capablanca wrote:
I have a problem with utf-8 enconding and I don't know
what to do in order to make it work.

I want to open a new window with excel data so the user
can choose to save it local. Everything works fine, the
new window, the excel data appears, but, extended
characters are wrong.


A quick test shows that Excel (XP) seems to be the problem. Excel blindly
opens any CSV file using the OS default codepage.
--
Joerg Jooss
jo*********@gmx.net

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Iain | last post by:
Folks, I'm having a problem with charset encodings that I desparately need some help with. I don't even pretend to know the basics about charsets, so please forgive my ignorance. I am...
1
by: Neet | last post by:
Hi, I am currently working on sending an XML request to a server and it responds with an xml response. This request and response use ISO-8859-1 encoding. The xml request and response need to match....
13
by: bussiere bussiere | last post by:
hi i'am making a program for formatting string, or i've added : #!/usr/bin/python # -*- coding: utf-8 -*- in the begining of my script but str = str.replace('Ç', 'C') str =...
7
by: EmeraldShield | last post by:
We have an application that uses UTF8 everywhere to load / save / process documents. One of our clients is having a problem with BIG Encoded files being trashed after running through our app. ...
0
by: kellner | last post by:
Hello, I'm parsing a chunk of XML code and would like to add attribute values to individual tags if these are lacking. This is with perl 5.8.6, libxml2 2.6.17, XML::LibXML 1.58. Basically, I...
4
by: WH | last post by:
Hi, I use a Streamreader in VB2005 to read text files I made before in NotePad, but it can't read characters like "é" or "ç". They are omitted, or replaced by other characters. I tried different...
10
by: amygdala | last post by:
Hi all, Another problem that has been bugging me for a while now, but which I swept under the rug too long too now is a mail encoding problem at my (shared) webhost. The problem is that on...
15
by: Bexm | last post by:
Hello I have searched through this forum and it seems some people are having similar problems to me but none of the fixes are fixing mine..! :( I have a table in my database that has two xml...
0
by: damonwischik | last post by:
I use emacs 22 and python-mode. Emacs can display utf8 characters (e.g. when I open a utf8-encoded file with Chinese, those characters show up fine), and I'd like to see utf8-encoded output from my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.