MemoryStream ms = new MemoryStream(); byte[] buffer = null; using (ZipFile file = ZipFile.Create(ms)) { file.BeginUpdate(); file.NameTransform = new MyNameTransform(); if (Directory.Exists(Path.GetDirectoryName(newpath))) { DirectoryInfo dir = new DirectoryInfo(newpath); FileInfo[] files=dir.GetFiles(); for (int i = 0; i < files.Length; i++) { file.Add(files[i].FullName); } } file.CommitUpdate(); buffer = new byte[ms.Length]; ms.Position = 0; ms.Read(buffer, 0, buffer.Length); } Response.ContentType = "application/octet-stream"; HttpBrowserCapabilities bc = Request.Browser; if (bc.Browser == "IE") { Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("考生照片.zip", System.Text.Encoding.UTF8)); } else { Response.AddHeader("Content-Disposition", "attachment; filename=考生照片.zip"); } Response.BinaryWrite(buffer); Response.Flush(); DeleteFolder(newpath); Response.End();
这个就是我把本地文件循环添加到ZipFile,在转换为数据流下载,在本地可以正常运行,部署到服务器上确出错。。
权限问题.?
能说的详细点吗,我这用的是IIS6.0
@潜者之意: 你看一下,是不是下载文件的目录缺少权限.?