Hi all,
I would like to dynamicly create a downloadable .csv file when visiting a page.
But it seems that no matter what i do, it seems my encoding is wrong, or at least i think it is the encoding that is the problem.
This is my code in the pagetemplate:
@using System.Web @using System.Text @{ string attachment = "attachment; filename=kampagne_data.csv"; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ContentType = "text/csv"; HttpContext.Current.Response.Charset = Encoding.UTF8.WebName; HttpContext.Current.Response.AddHeader("Content-type", "application/vnd.ms-excel"); HttpContext.Current.Response.AddHeader("Content-Disposition", attachment); HttpContext.Current.Response.AddHeader("Pragma", "must-revalidate"); HttpContext.Current.Response.AddHeader("Cache-Control", "must-revalidate"); HttpContext.Current.Response.Write("Test;Test2;Test3;æøåÆØÅ"); HttpContext.Current.ApplicationInstance.CompleteRequest(); // instead of Response.End() } To be able to use the template as a pagetemplate i have the below code in the bottom of the template (seems the masterpage tag is required): @if(1 == 2) { <div title="Indhold" id="campaign-content-container" class="col-xs-12 dwcontent"></div> }<!--@MasterPageFile(Lead_Export_Master.cshtml)--> <!--@Layout.Title(Kampagne export)-->
Any help how i get the data exported correctly is much appreciated, and not looking like weird characters.