Asp.net for simple download

Source: Internet
Author: User

Asp.net for simple download

Today, I encountered a problem when I used asp.net for download. I couldn't find the web path on the server, but I knew the absolute path of the file from the server.

Therefore, a new page is created and uploaded to the server. Click Download to jump to the page. You can download the local file on the page.

The page code is as follows:

1 1 string url = "file name .doc" 2 2 string DownloadTitle = "title"; 3 3 string downpath = "E:/Tiku_Soft/" + url; 4 4 4 HttpContext. current. response. contentType = "application/ms-download"; 5 5 string s_path = downpath. trim (); 6 6 System. IO. fileInfo file = new System. IO. fileInfo (s_path); 7 7 HttpContext. current. response. clear (); 8 8 HttpContext. current. response. addHeader ("Content-Type", "application/octet-stream"); 9 9 HttpContext. current. response. charset = "UTF-8"; 10 10 HttpContext. current. response. addHeader ("Content-Disposition", "attachment; filename = \" "+ DownloadTitle + ". doc "+" \ ""); 11 11 HttpContext. current. response. addHeader ("Content-Length", file. length. toString (); 12 12 HttpContext. current. response. writeFile (file. fullName. trim (); 13 13 HttpContext. current. applicationInstance. completeRequest ();

 

Related Article

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.