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 ();