下载文件ZIP奇怪的出错,页面忽闪,没戏了?

heartche88 2008-11-22 01:18:02
功能是这样的 :页面上有文件和文件夹,可以实现单个文件的下载

当用户点击多个文件时候需要做一个压缩,我的思路是调用7z.exe(一个工具) 压缩批量文件 放置到一个当前用

户根据sessionID产生的唯一文件夹中(如果这个文件夹存在删除它,否则创建并将zip文件放置其中) 剩下要做的事情就是开一个

新页面,response.redirect(将唯一文件夹连同.zip文件名的完整路径 ,true )

然而 奇怪的是调试的时候是可以产生下载对话框的,正常运行的时候却 页面一闪,啥都没有,郁闷 ,ZIP文件是有的

昨天找到说是缓存的问题,试了下,也不确定,请高手帮我指点一下,到底问题出在哪里 ?
...全文
124 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
pgameli 2008-11-25
  • 打赏
  • 举报
回复
mark
heartche88 2008-11-25
  • 打赏
  • 举报
回复
已经解决了,原来是

System.IO.FileInfo file = new System.IO.FileInfo(pathAndFileName);
if (file.Exists)
{


}
只要去掉这个就可以了。条件不正确,所以导致运行的时候进去不了,但为什么调试的时候可以进去,运行的时候不能进去还没弄明白。。。

icerain911 2008-11-24
  • 打赏
  • 举报
回复
在下载前让他睡上一下 SLEEP(1000)
heartche88 2008-11-24
  • 打赏
  • 举报
回复
在page_load里先判断有没有批量下载,有批量下载就弹出一个JS ,新窗口,去下载,后面再绑定datagrid

是什么原因造成的呢 ?调试的时候是100%可以弹出下载提示的对话框,正常运行一闪就没有结果了,郁闷!公司里的高手也一筹莫展。。。
gavinluo 2008-11-24
  • 打赏
  • 举报
回复
如果本机调试可以,放到服务器上不行,那就是服务器环境的问题了
有没有启用父路径,文件映射里是不是把zip映射到其他程序了
heartche88 2008-11-24
  • 打赏
  • 举报
回复
不是吧

在page_load里先判断有没有批量下载,然后再绑定
踏平扶桑 2008-11-24
  • 打赏
  • 举报
回复
是不是目录的权限问题
heartche88 2008-11-22
  • 打赏
  • 举报
回复
#region 批量下载
if (IsPostBack && tbxDelSelectedFlag.Text == "TRUE")
{
System.IO.DirectoryInfo ad=new System.IO.DirectoryInfo(this.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["mapPath"].ToString())+@"\"+this.Session.SessionID);
if(ad.Exists)
{
ad.Delete(true);

}
string path=dir;
#region
for (int i=0; i<this.dgrid.Items.Count; i++)
{
string a=this.dgrid.Items[i].Cells[5].Text;
CheckBox cbxDel = (CheckBox)dgrid.Items[i].Cells[5].FindControl("cbxDelItem");
System.Collections.ArrayList files=new ArrayList();//保存要下载的文件或文件夹信息

if (cbxDel.Checked)
{
client.RemoteHost="127.0.0.1";
client.RemotePass="abstest";
client.RemotePath=dir;
client.RemotePort=2121;
client.RemoteUser="abstest";

string user= this.Session["UserChName"].ToString();
string mapPath=this.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["mapPath"].ToString());// 配置的物理地址
string sid=this.Session.SessionID;
//获得选中的文件名或者文件夹名
string fileName= dgrid.Items[i].Cells[2].Text.Trim();

if(this.dgrid.Items[i].Cells[1].Text=="1") //文件
{

files.Add(this.dgrid.Items[i].Cells[2].Text.Trim());
}

// 将FTP上的文件下到WEB服务器
System.IO.DirectoryInfo ad2=new System.IO.DirectoryInfo(this.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["mapPath"].ToString())+@"\"+this.Session.SessionID);

if(!ad2.Exists)
{
ad2= System.IO.Directory.CreateDirectory(mapPath+@"\"+sid);//指定当前用户生成一个唯一的文件夹
}
this.Session["dire"]=ad.FullName ;// 保存 到文件夹的 完整目录

if(ad2.Exists)
{
client.Get2(path,fileName,this.Session["dire"].ToString(),fileName,access);//执行下载
}
else
{
this.Response.Write("<script>alert('WEB服务器上创建目录失败!')</script>");
}

}
}
#endregion
//this.Session["forDeleteDir"]=this.Session["dire"].ToString();

//将服务器上的文件压缩包起来
string abc= this.Server.MapPath(@"~\filedown\")+"7z.exe a "+ this.Session["dire"].ToString()+"\\"+this.Session.SessionID+".zip "+this.Session["dire"].ToString()+"";
//System.Diagnostics.Process.Start(this.Server.MapPath(@"~\filedown\")+"7z.exe a "+ this.Session["dire"].ToString()+this.Session.SessionID+".zip "+this.Session["dire"].ToString()+"");
System.Diagnostics.Process.Start(this.Server.MapPath(@"~\filedown\")+"7z.exe "," a "+ this.Session["dire"].ToString()+"\\"+this.Session.SessionID+".zip "+this.Session["dire"].ToString());
// 将 WEB服务器上的文件下载到客户端
string pathAndFileName=this.Session["dire"].ToString()+@"\"+this.Session.SessionID +".zip";
// string url=System.Configuration.ConfigurationSettings.AppSettings["mapPath"].ToString()+@"\"+this.Session.SessionID+@"\"+this.Session.SessionID+".zip";
string url= "./tempfiles/"+this.Session.SessionID+"/"+this.Session.SessionID+".zip";

//url = url.Replace("\\","/");
// url = url.Replace("~","./");
//url=url.Replace("//","/");

System.IO.FileInfo file = new System.IO.FileInfo(pathAndFileName);
if (file.Exists)
{
// bool succeed= this.ZIPDown(pathAndFileName,"");// 调用下载文件的方法ZIPDown()
string aaa = "<script language='javascript'>window.open('"+url+"','_blank')</script>";
aaa= "<script>top.location.href='"+url+ "'</script>";
//this.Response.Write(aaa);
// this.Response.Write("<script>top.location.href='"+url+ "'</script>");
this.Response.Redirect(url,true);

}
// else
// {
// this.Response.Write("<script>alert('文件不存在!')</script>");
// }

System.IO.DirectoryInfo dired=new System.IO.DirectoryInfo(this.Session["dire"].ToString());
if(dired.Exists)
{
client.DisConnect();
}

tbxDelSelectedFlag.Text = "FALSE";
}
else
{
tbxDelSelectedFlag.Text = "FALSE";
}

#endregion

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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