標籤:style blog http io color ar os sp strong
asp.net中的一個簡單的下載,只需將檔案路徑引入就能實現下載,
比如一個本地檔案 <a href="file:/C:/蒼老師.jpg"></a>
網頁上的下載也是如此 http://w.x.baidu.com/alading/anquan_soft_down_normal/12350
今天下載碰到一個問題,找不到伺服器上的web路徑,但是從伺服器上知道了檔案的絕對路徑
於是建立了一個頁面上傳到伺服器,點擊下載跳轉到該頁面,在頁面上擷取到本地檔案就能進行下載
頁面代碼如下:
1 1 string url = "檔案名稱.doc" 2 2 string DownloadTitle = "標題"; 3 3 string downpath = "E:/Tiku_Soft/" + url; 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();
關於asp.net簡單的下載問題