C# 将多个crystal reports PDF添加到zip文件

C# 将多个crystal reports PDF添加到zip文件,c#,crystal-reports,dotnetzip,C#,Crystal Reports,Dotnetzip,我正在尝试将pdf文件从Crystal导出到streams,然后我想使用DotNetZip库将它们(总共7个)添加到zip文件中。我只是想在下面添加一个。我有一种感觉,我走远了。请帮忙 MemoryStream oStream; CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); if (a2batch.C

我正在尝试将pdf文件从Crystal导出到streams,然后我想使用DotNetZip库将它们(总共7个)添加到zip文件中。我只是想在下面添加一个。我有一种感觉,我走远了。请帮忙

MemoryStream oStream;
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

if (a2batch.Count > 0) // a2batch - My Crystal Datasource List
{
    rpt.Load(Server.MapPath("~\\Report\\Construction\\ScheduleA2.rpt"));
    rpt.SetDataSource(a2batch);
    oStream = (MemoryStream)rpt.ExportToStream(ExportFormatType.PortableDocFormat);
    using (ZipFile zipFile = new ZipFile())
    {
        zipFile.AddEntry("Report.pdf", oStream);
        zipFile.Save("Report.zip");
    }
}

你问题中的代码有效吗?如果是这样,最简单的方法可能是在添加其他流时打开zip文件:

using (ZipFile zip = ZipFile.Read(ExistingZipFile)) 
然后使用与问题中相同的代码添加新文件,然后使用以下代码保存:

zip.Save();
您可以随意将文件添加和删除到现有的zip存档中。如果使用相同的方法创建所有流,也可以在关闭文件之前添加多个流中的数据,即在每个流之后添加多个zip.AddEntry语句