首页 > 代码库 > 关于asp.net简单的下载问题
关于asp.net简单的下载问题
asp.net中的一个简单的下载,只需将文件路径引入就能实现下载,
比如一个本地文件 <a href="http://www.mamicode.com/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个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。