首页 > 代码库 > SharpZipLib 压缩文档下载
SharpZipLib 压缩文档下载
using ICSharpCode.SharpZipLib.Zip; Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); //创建压缩输出流 ZipOutputStream zos = null; //创建内存流 MemoryStream ms = null; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip"); ms = new MemoryStream(); //关联压缩流和内存流 zos = new ZipOutputStream(ms); string strEntryName = fileName + ".pdf"; //创建压缩的对象实体放入压缩流,可循环创建 foreach (string file in filenames) { ZipEntry entry = new ZipEntry(Path.GetFileName(file)); entry.DateTime = DateTime.Now; zos.PutNextEntry(entry); using (FileStream fs = File.OpenRead(file)) { int sourceBytes; do { sourceBytes = fs.Read(buffer, 0, buffer.Length); zos.Write(buffer, 0, sourceBytes); } while (sourceBytes > 0); } } zos.Finish(); zos.Close(); Response.BinaryWrite(ms.ToArray()); Response.End();
SharpZipLib 压缩文档下载
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。