working sample [ c# , using vs 2015 cm]- [as per your point ..... no more files .in server]
1) crystalreports added to sample-project named as "CrystalReport1.rpt , CrystalReport2.rpt" [ simple design]
2) Required Files : ( merging streams) itext lib : https://www.nuget.org/packages/iTextSharp ( command :: Install-Package iTextSharp -Version 5.5.11)
3) Required Namespace
using System;
using System.IO;
using System.Collections.Generic;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using iTextSharp.text;
using iTextSharp.text.pdf;
Step 1: Reference code
//reploace this event to your related event .......
protected void Page_Load(object sender, EventArgs e)
{
//hold the more than one report outputs [bytes]
List<byte[]> files = new List<byte[]>();
//for testing purpose LOOP used,
//u can change as per your requirement and your report name
for (int i = 1; i <= 2; i++) {
ReportDocument crdReport1 = new ReportDocument();
//put your related report names.....
crdReport1.Load(Server.MapPath(string.Format("CrystalReport{0}.rpt", i)));
Stream stream1 = crdReport1.ExportToStream(ExportFormatType.PortableDocFormat);
//prepare the "bytes" from "stream"
files.Add(PrepareBytes(stream1));
//finally the result added to LIST
}
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
//merge the all reports & show the reports
Response.BinaryWrite(MergeReports(files).ToArray());
Response.End();
}
Step 2: Reference code (credits :: https://stackoverflow.com/a/221941 )
//prepare the report bytes
private byte[] PrepareBytes(Stream stream)
{
using (MemoryStream ms = new MemoryStream())
{
byte[] buffer = new byte[stream.Length];
int read;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
Step 3: Reference code ( credits :: https://stackoverflow.com/a/6780582 )
//Merge the reports
private MemoryStream MergeReports(List<byte[]> files)
{
if (files.Count > 1)
{
PdfReader pdfFile;
Document doc;
PdfWriter pCopy;
MemoryStream msOutput = new MemoryStream();
pdfFile = new PdfReader(files[0]);
doc = new Document();
pCopy = new PdfSmartCopy(doc, msOutput);
doc.Open();
for (int k = 0; k < files.Count; k++)
{
pdfFile = new PdfReader(files[k]);
for (int i = 1; i < pdfFile.NumberOfPages + 1; i++)
{
((PdfSmartCopy)pCopy).AddPage(pCopy.GetImportedPage(pdfFile, i));
}
pCopy.FreeReader(pdfFile);
}
pdfFile.Close();
pCopy.Close();
doc.Close();
return msOutput;
}
else if (files.Count == 1)
{
return new MemoryStream(files[0]);
}
return null;
}
so, you can change the logic in step : 1 ( as per you reports )