目前代码如下: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();
}在网上找过很多种方法 都不行~ 恳请高手指点~~~ 谢谢啦~~ 急~
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();
}在网上找过很多种方法 都不行~ 恳请高手指点~~~ 谢谢啦~~ 急~
解决方案 »
- 关于aspc和cs后台代码文件访问类库DLL中的internal类的问题
- 重写事件OnInit 导致"此网页包含重定向循环"
- 征集<script></script>标签动态加载
- 请高手指点ASP.NET的GridView问题!
- 请问如何在Ms Sql Server中添加一条记录后立即得到其标识列
- 大家讨论邮件下载后要不要存储在数据库里,不存好像都从邮件服务器读不能解决邮件是否是新邮件的问题
- hotmail的Smtp是什么?
- 有关运行gotdotnet.com网站的问题!
- 找寻.NET做的大型网站,想给自己点信心.大家一起顶!
- 刚做完个网站,大家给点意见吧!来者有分!(
- 很奇怪的问题,asp.net回传后,textbox的值变成乱码
- ASP.net Unicode转换为Native
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(); //将当前所有缓冲的输出发送到客户端
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();
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();
}试试这个。
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();
}