asp.net 文件下载功能,如果电脑上装有迅雷,会下载页面的源码 (急)
时间:2010-06-11
来源:互联网
string path = System.Web.HttpContext.Current.Request.PhysicalApplicationPath+"uploadFile/部门文件夹/"+dept+"/"+XFileName;
//初始化 FileInfo 类的实例,它作为文件路径的包装
FileInfo fi = new FileInfo(path);
//判断文件是否存在
if (fi.Exists)
{
//将文件保存到本机上
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename="+System.Web.HttpUtility.UrlEncode(filename,System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName);
Response.End();
}
在网上找过很多种方法 都不行~ 恳请高手指点~~~ 谢谢啦~~ 急~
作者: zhuangxianbo2009 发布时间: 2010-06-11
作者: tianshikuqi8 发布时间: 2010-06-11
作者: zhuangxianbo2009 发布时间: 2010-06-11
我也碰到过类似的问题,看了这个后解决了参考
好东西。。。
作者: Seven_lau 发布时间: 2010-06-11
作者: zhuangxianbo2009 发布时间: 2010-06-11
作者: foren_whb 发布时间: 2010-06-11
你可以试一下
C# code
string RECORDFILE; string http; RECORDFILE = Request["RECORDFILE"].Replace("|", ""); http = "/down/"; FileInfo DownloadFile = new FileInfo(http+RECORDFILE); //设置要下载的文件 Response.Clear(); //清除缓冲区流中的所有内容输出 Response.ClearHeaders(); //清除缓冲区流中的所有头 Response.Buffer = false; //设置缓冲输出为false //设置输出流的 HTTP MIME 类型为application/octet-stream Response.ContentType = "application/octet-stream";//将 HTTP 头添加到输出流 Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8)); //Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());//将指定的文件直接写入 HTTP 内容输出流。 //Response.WriteFile(DownloadFile.FullName); Response.WriteFile(http + RECORDFILE); Response.Flush(); //向客户端发送当前所有缓冲的输出 Response.End(); //将当前所有缓冲的输出发送到客户端
作者: ly302 发布时间: 2010-06-11
FileStream f= new FileStream("", FileMode.Open);
byte[] buffer = new byte[f.Length];
f.Read(buffer, 0, buffer.Length);
f.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("", System.Text.Encoding.UTF8));
Response.BinaryWrite(buffer);
Response.Flush();
Response.End();
作者: wuyq11 发布时间: 2010-06-11
作者: a19895161989516 发布时间: 2010-06-11
作者: qiqishardgel 发布时间: 2010-06-12
作者: renpinghao 发布时间: 2011-05-31
private void Filedown() { string url = Server.MapPath("drop.htm"); FileStream f = new FileStream(url, FileMode.Open); byte[] buffer = new byte[f.Length]; f.Read(buffer, 0, buffer.Length); f.Close(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8)); Response.BinaryWrite(buffer); Response.Flush(); Response.End(); }
试试这个。
作者: lirenniao 发布时间: 2011-05-31

作者: fk1984316 发布时间: 2011-05-31
作者: dianachen2 发布时间: 2011-05-31
作者: loveljsheng 发布时间: 2011-05-31
作者: szjarvis 发布时间: 2011-08-31
string filename=Request.QueryString(["filename"]);
FileInfo DownloadFile = new FileInfo("../FILE/"+filename); //设置要下载的文件
if(DownloadFile.isExists)
{
Response.Clear(); //清除缓冲区流中的所有内容输出
Response.ClearHeaders(); //清除缓冲区流中的所有头
Response.Buffer = false; //设置缓冲输出为false
Response.ContentType = "application/octet-stream";//将 HTTP 头添加到输出流
Response.AppendHeader("Content-Disposition", "attachment;filename=" +HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush(); //向客户端发送当前所有缓冲的输出
Response.End(); //将当前所有缓冲的输出发送到客户端
Response.Close();
}
作者: hongyanjava 发布时间: 2011-12-06
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28