下载时不能弹出提示用户保存的对话框,急!!!!

liujuanwh 2005-11-04 12:04:17
在我这里调试都能下载,放到服务器上后就是不能弹出提示框,只是又弹出一个和本页一样的页面,点击下载按钮没有反应,好像只会刷新界面
...全文
272 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChengKing 2005-11-04
  • 打赏
  • 举报
回复
可能是文件名路径的问题吧. F9跟踪一下文件路径,看能不能根据路径找到要下载的文件

/// <summary>
/// 文件下载
/// </summary>
/// <param name="FullFileName"></param>
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
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();
}
lc411895514 2005-11-04
  • 打赏
  • 举报
回复
可能是路径的问题,要用相对路径,如果不知道什么是相对路径,可进入http://www.webshu.com/tutorial/tor/7,id=0401.htm
查看
renyu732 2005-11-04
  • 打赏
  • 举报
回复
代码贴出来.
liujuanwh 2005-11-04
  • 打赏
  • 举报
回复
找到问题症结了,原来我用的相对路径不能下,我把它改成绝对路径了。因为以前都是放在wwwroot下,这次放到e:\盘下,所以路径不对,他可能找不到文件下载。换成绝对路径后能下载了,谢谢 lc411895514(禾日) 和 ChengKing(Enthusiasm Bigrosoft) ,感谢大家
liujuanwh 2005-11-04
  • 打赏
  • 举报
回复
路径已经是相对路径了,下载代码
public void Save()
{
if (System.IO.File.Exists(fileName))
{
FileInfo DownloadFile = new FileInfo(fileName);
System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.ClearHeaders(); System.Web.HttpContext.Current.Response.Buffer=false;
System.Web.HttpContext.Current.Response.Charset = "GB2312"; System.Web.HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.UTF8;
System.Web.HttpContext.Current.Response.ContentType="application/octet-stream";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" +System.Web.HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
// System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
// System.Web.HttpContext.Current.Response.Flush();
// System.Web.HttpContext.Current.Response.End();//原来的程序
byte[] tmpbyte=new byte[1024*8];
System.IO.FileStream fs=DownloadFile.OpenRead();
int count;
while((count=fs.Read(tmpbyte,0,tmpbyte.Length))>0)
{
System.Web.HttpContext.Current.Response.BinaryWrite(tmpbyte); System.Web.HttpContext.Current.Response.Flush();
}
fs.Close();
System.Web.HttpContext.Current.Response.End();
}
}

都是按照大家的说法写的。可是我感觉跟代码没关系,因为我安装在本机和别的机器上用都是好的,安装到那台服务器上就是不能弹出保存框,它就只刷新页面,我估计是不是跟那台机器的设置有关系
软件微工厂 2005-11-04
  • 打赏
  • 举报
回复
同意ChengKing(Enthusiasm Bigrosoft) ,把下载的文放到另一个页面,设置返回的字节流就可以了

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧