public void ProcessRequest (HttpContext context)
{
DownloadFile ("tutorial. csv", "a.csv");
Context. Response.Charset = "UTF-8";
Context. response.contentencoding = System.Text.Encoding.UTF8;
Context. response.headerencoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "Application/octet-stream";
HttpContext.Current.Response.AddHeader ("Content-disposition", "attachment;filename=" + Httputility.urlencode (" Test. csv "));
Context. Response.BinaryWrite (new byte[] {0xEF, 0xBB, 0xBF});
Context. Response.Write ("number, name \n1, Di Meng");
Context. Response.Flush ();
Context. Response.End ();
}
#region provide the file download method "limited to files that already exist on the server side"
<summary>
Provides a way to download files "limited to files that already exist on the server side"
</summary>
<param name= "FileName" > must have a suffix name. Download the name of the file when saving, can be different from the actual file name, can be Chinese </param>
<param name= "FilePath" > The virtual path of the file to download </param>
public void DownloadFile (string fileName, String filePath)
{
HttpContext.Current.Response.ContentType = "Application/octet-stream";
HttpContext.Current.Response.AddHeader ("Content-disposition", "attachment;filename=" + httputility.urlencode ( FileName));
HttpContext.Current.Response.WriteFile (FilePath);
}
#endregion
Web Export CSV