this one turns me on. And last week I took apart the nut, but, unfortunately, not ...
so I want to create a CSV download for other users so that they open in MS-Word (they want the CSV format)
so I get this code in MVC2 controller:
Response.AddHeader("Content-Disposition", "attachment; filename=PersonalMessages.csv"); Response.ContentType = "application/csv"; string s = new DownloadService().GetAddresses(); Response.Write(s); Response.End(); return null;
the string 's' contains (among other information) these characters: é å æ É à
When I open it in notepad: OK
when I open it in Notepad ++: Ok
when I open it in Excel: not ok, it shows it: Ã © Ã ¥ Ã | Ã ‰ Ã
(when I open it in Notepadd ++, it says that it is in UTF8 encoding without specification, no matter what I tried with UTF8 encodings with boolean in constructor, to get the specification, it did not work)
So, I asked a question last week, and the answer was that the GetAddresses () function would return a byte array.
So, I converted my text using this:
// C
and wrote an array of bytes in the response, and everything was fine! Notepad, Notepad ++ and Excel! Great, live well.
But then I found out that we open the file in Word. Well, no problem, I thought.
But then they help: Word cannot open the file (directly), it asks for the first encoding , and this is a problem because they use it in an automatic process.
When they open the file in Notepad and save it as Unicode, everything goes well.
I also tried this in the action method:
Response.ContentEncoding = Encoding.Unicode ; Response.HeaderEncoding = Encoding.UTF8;
but it did not help.
Are there any clues?