新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
利用Asp.net怎么實現(xiàn)一個文件下載功能-創(chuàng)新互聯(lián)
本篇文章給大家分享的是有關(guān)利用Asp.net怎么實現(xiàn)一個文件下載功能,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
首先有一個html頁面,頁面有一個鏈接,點擊鏈接彈出文件下載/保存(類似迅雷下載鏈接)
文件下載 下載readme.txt文件
下載readme.txt文件
一般處理程序的代碼如下
using System.IO; using System.Web; namespace Zhong.Web { ////// DownloadFileHandler 的摘要說明 /// public class DownloadFileHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { string filePath = context.Server.MapPath("~/App_Data/readme.txt"); FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Dispose(); context.Response.ContentType = "application/octet-stream"; context.Response.AddHeader("Content-Disposition", "attachment; filename=readme.txt"); context.Response.BinaryWrite(bytes); context.Response.Flush(); //大文件下載的解決方案 //context.Response.ContentType = "application/x-zip-compressed"; //context.Response.AddHeader("Content-Disposition", "attachment;filename=z.zip"); //string filename = Server.MapPath("~/App_Data/move.zip"); //context.Response.TransmitFile(filename); } public bool IsReusable { get { return false; } } } }
以上就是利用Asp.net怎么實現(xiàn)一個文件下載功能,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享文章:利用Asp.net怎么實現(xiàn)一個文件下載功能-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://www.ef60e0e.cn/article/gjsoe.html