0

I'm trying to export the pdf files from Crystal to streams, then I want to add them (7 total) to a zip file using the DotNetZip Library. I'm just trying to add one below. I have a feeling I'm way off. Please help.

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");
    }
}

1 Answers1

0

Does the code in your question work? If so, the easiest is probably to just open the zip file when you add the other streams:

using (ZipFile zip = ZipFile.Read(ExistingZipFile)) 

Then use the same code as in you question to add the new file, and then save it with:

zip.Save();

You can add and remove files to an existing zip archive at will. If you are creating all the streams in the same method, it is also possible to just add data from several streams before you close the file, that is adding several zip.AddEntry statements after each other.

BlackCat
  • 156
  • 1
  • 8