日期:2014-05-18  浏览次数:21040 次

压缩文件时能先弹出提示框吗?然后在压缩。求高手。等答案。
压缩前为什么不弹出提示框。怎样可以弹出提示语?  
调用方法 :
(1)Response.Write("<script>alert('AAA');</script>");
  dlZipDir(userPath, photos);
(2)
  dlZipDir(userPath, photos);
  Response.Write("<script>alert('AAA');</script>");
都不能弹出提示语, 求高手解答

控件 ICSharpCode.SharpZipLib.dll
代码如下
  /// <summary>
  /// 压缩
  /// </summary>
  ZipOutputStream zos = null;
  String strBaseDir = "";
  public void dlZipDir(string strPath, string strFileName)
  {
  MemoryStream ms = null;
  Response.ContentType = "application/octet-stream";
  strFileName = HttpUtility.UrlEncode(strFileName).Replace('+', ' ');
  Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName + ".zip");
  ms = new MemoryStream();
  zos = new ZipOutputStream(ms);
  strBaseDir = strPath + "\\";
  addZipEntry(strBaseDir);

  zos.Finish();

  zos.Close();

  Response.Clear();

  Response.BinaryWrite(ms.ToArray());

  Response.End();
  }

  //压缩
  public void addZipEntry(string PathStr)
  {
  DirectoryInfo di = new DirectoryInfo(PathStr);
  foreach (DirectoryInfo item in di.GetDirectories())
  {
  addZipEntry(item.FullName);

  }
  foreach (FileInfo item in di.GetFiles())
  {
  FileStream fs = File.OpenRead(item.FullName);
  byte[] buffer = new byte[fs.Length];
  fs.Read(buffer, 0, buffer.Length);
  string strEntryName = item.FullName.Replace(strBaseDir, "");
  ZipEntry entry = new ZipEntry(strEntryName);
  zos.PutNextEntry(entry);
  zos.Write(buffer, 0, buffer.Length);
  fs.Close();
  }
  }

------解决方案--------------------
需要增加一个线程 就可以了
------解决方案--------------------
可以的 结合JS,你JS先写好了 放到页面里 然后后台调用 !
------解决方案--------------------
要改前台开始下载的地方,比如:

<asp:Button runat="server" OnClick="Btn_Click" Text="下载" OnClientClick="alert('AAA');" />

------解决方案--------------------
Response.Write("<script>alert('AAA');location='zip.aspx';</script>");

zip.aspx执行压缩