Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Issues saving HTML with Content-Disposition

Author  Topic 

raulbolanos
Starting Member

6 Posts

Posted - 2010-08-02 : 16:37:20
Hi guys, I have some issues, saving a HTML content into Excel format. I just populate a StringBuilder and then display it into a WebControl Panel, juzt like this:

resultados.Controls.Add(new LiteralControl(sb.ToString()));

And then I set the ContentType and I add a header to download the content. This is the code:


Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=Indicador.xls");
Response.ContentEncoding = Encoding.UTF8;
Response.Charset = "";
Response.Write(sb.ToString());

The data that I get from the database, which I display into the StringBuilder. Sometimes the whole document get disturbed with strange characteres, like if it wasn´t UTF-8 text.

It's very strange and it happened to me a lot of times and I want to know once and for all what is happening.

This is one example of the text that causes the whole mess.


"La tasa está calculada a mitad del período. La etiqueta 1987 representa el período 1987-1992. La etiqueta 1992 representa el período 1992-1997. La etiqueta 1997 representa el período 1997-2002. La etiqueta 2004 representa el período 2004-2009."

As you can see, it's spanish and it may be because the accents.

If I only take till the second sentences, it doesn't happend, and you can realize that "está" and "período" have accent. Therefore it's not because the accent.

Afterwards, I take till the third sentence and everything get into a mess... and I can't find what is happening. There must be some special characteres, that I cannot see? Also de fourth sentence make some noise on the document.

¿What is going on with the encoding process?

I will really appreciate if you could advise me some how.

Thank you in advance.

Raul Bolaños.
   

- Advertisement -