關於asp.net簡單的下載問題

來源:互聯網
上載者:User

標籤: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簡單的下載問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.