日期:2014-05-17 浏览次数:20523 次
//WriteFile实现下载
string fileName = "ceshi.rar";//客户端保存的文件名
string filePath = Server.MapPath("keji.rar");//路径
FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
------解决方案--------------------
httpHanlder你不会写?这是asp.net开发的基础知识啊
httpHanlder就是一个cs文件类。然后在web。config里面注册。iis中添加通配符应用程序映射
就可以截取任何类型的文件,根据你的下载的文件夹位置判断是不是访问了下载的文件。
例子
参见
http://msdn.microsoft.com/zh-cn/library/ms227439.aspx