关于asp.net简单的下载问题

    关于asp.net的下载,只需将打开相应的文件路径就能在浏览器上实现下载功能,比如项目的同级目录上有一个文件 苍老师.zip<a href="苍老师.zip"></a>

    点击a标签就能下载这个文件。

    但是今天用asp.net做一个下载碰到一个问题,找不到服务器上的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();

 

转载于:https://www.cnblogs.com/brilliant/p/4088991.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值