c#导出压缩包到浏览器

        public FileStream BatchExport()
        {
//HttpUtility.UrlEncode是用来解决ie浏览器乱码问题
            Response.AddHeader("content-disposition", "attachment;filename="+ HttpUtility.UrlEncode("证件照") + ".zip");//"+ DateTime.Now.ToString("yyyyMMddHHmmss") + "
            //Zip文件流 不用using的话会出现文件被占用的情况
            using (FileStream zipFile = System.IO.File.Create(Server.MapPath((string)path) + "/证件照.zip"))
            {
                ZipOutputStream zipStream = new ZipOutputStream(Response.OutputStream);
//循环数据库数据通过fastreport生成文件流并写入压缩文件中,关于fastreport的生成方法省略
foreach (member Info in MemberList)
                    {

                        MemoryStream strm = new MemoryStream();

                        report.Export(new PDFExport(), strm);//PDFExport//ImageExport()
                        strm.Position = 0;

                        byte[] bytes = new byte[(int)strm.Length];
                        strm.Read(bytes, 0, bytes.Length);
                        strm.Close();
                        var zipEntry = new ZipEntry(info.id+".pdf");
                        zipStream.PutNextEntry(zipEntry);
                        zipStream.SetLevel(5);
                        zipStream.Write(bytes, 0, bytes.Length);
                    }

zipStream.Finish();
                return zipFile;
}
}

参考网址:

关于文件被占用问题解决方法

https://blog.csdn.net/qq_28215385/article/details/78591973

IE浏览器下载文件中文乱码

https://blog.csdn.net/weiyucai0323/article/details/8255676

导出压缩包到浏览器页面

https://www.cnblogs.com/luna-hehe/p/10101087.html

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值