C# Response CSV - JackHu88/Comm GitHub Wiki

string folder= @"C:\Test;
string fileName = "test" + ".csv";
string filePath = Path.Combine(folder, fileName);
builder.AppendLine("head,EntityCode,DEBIT,DOUBLEMSGCHAR");
using (var w = new StreamWriter(filePath))
{
    w.WriteLine(builder.ToString());
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
HttpContext.Current.Response.Write(builder.ToString());
//Response.End();
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();