Web Export CSV

Source: Internet
Author: User
Tags httpcontext urlencode

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.