Created
January 6, 2016 19:43
-
-
Save miklund/5b593c2e50059920a96d to your computer and use it in GitHub Desktop.
2011-04-20 UTF8 encoding and Excel CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: UTF8 encoding and Excel CSV | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2011/04/20/utf8-encoding-and-excel-csv.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ProcessRequest(HttpContext context) | |
{ | |
context.Response.ContentEncoding = Encoding.UTF8; | |
context.Response.ContentType = "text/csv"; | |
context.Response.AppendHeader("Content-Disposition", "attachment;filename=data.csv"); | |
// Start the feed with BOM | |
context.Response.BinaryWrite(Encoding.UTF8.GetPreamble()); | |
var data = new[] | |
{ | |
"Namn;Land;Poäng", // Name;Country;Points | |
"Mikael Lundin;Sverige;1200", | |
"John Smith;US;800", | |
"Jean-Pierre Bordeaux;Française;600" | |
}; | |
foreach (var rows in data) | |
context.Response.Write(rows + "\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment