• 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();       
    

      

  • 相关阅读:
    虚函数******
    C++ 中的运算符重载********
    继承
    静态成员和成员函数
    类指针
    内联函数
    k8基础架构
    cobbler自动装机
    ens33-eth0
    PXE-自动装机配置
  • 原文地址:https://www.cnblogs.com/ITCoNan/p/6004613.html
Copyright © 2020-2023  润新知