Skip to content

Instantly share code, notes, and snippets.

@miklund
Created January 6, 2016 19:43
Show Gist options
  • Save miklund/5b593c2e50059920a96d to your computer and use it in GitHub Desktop.
Save miklund/5b593c2e50059920a96d to your computer and use it in GitHub Desktop.
2011-04-20 UTF8 encoding and Excel CSV
# Title: UTF8 encoding and Excel CSV
# Author: Mikael Lundin
# Link: http://blog.mikaellundin.name/2011/04/20/utf8-encoding-and-excel-csv.html
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