I have an ActionResult that returns a FileContentResult that is working fine.
byte[] report is returning LocalReport.Render("PDF", deviceInfo) of an rdlc.
The customer has requested a button on the page where they can get a whole bunch of these reports merged into 1 file.
The merge files method:
The problem is that no file is downloaded at all.
Everything seems to be working properly, I can step through the code all the way through returning the FileContentResult with no problems.
Anyone have any ideas as to what's wrong with the way I'm trying to do this or have a different approach to merging the files?
c# Code:
[AllowAgencyUser] public ActionResult TrainingHours(int id) { EmployeeModel model = new EmployeeModel(id); if (!model.CheckEmployeeAccess()) throw new HttpException(403, "Access Denied"); byte[] report = model.GetTrainingHoursReport(id); return File(report, Constants.PdfMimeType, model.EmployeeHoursReportFileName); }
byte[] report is returning LocalReport.Render("PDF", deviceInfo) of an rdlc.
The customer has requested a button on the page where they can get a whole bunch of these reports merged into 1 file.
c# Code:
[AllowAgencyUser] public ActionResult MassTrainingHours(int[] employeeIds) { if (employeeIds == null) return new EmptyResult(); List<byte[]> reportsList = new List<byte[]>(); foreach (int employeeId in employeeIds) { EmployeeModel model = new EmployeeModel(employeeId); byte[] fileBytes = model.GetTrainingHoursReport(employeeId); reportsList.Add(model.GetTrainingHoursReport(employeeId)); } PdfMerger merger = new PdfMerger(); byte[] report = merger.MergeFiles(reportsList); return File(report, Constants.PdfMimeType, "training_hours.pdf"); }
The merge files method:
c# Code:
public byte[] MergeFiles(List<byte[]> inputFiles) { MemoryStream outputMS = new MemoryStream(); Document document = new Document(); PdfCopy writer = new PdfCopy(document, outputMS); PdfImportedPage page = null; document.Open(); foreach (byte[] fileData in inputFiles) { PdfReader reader = new PdfReader(fileData); int n = reader.NumberOfPages; for (int i = 1; i <= n; i++) { page = writer.GetImportedPage(reader, i); writer.AddPage(page); } PRAcroForm form = reader.AcroForm; if (form != null) writer.CopyAcroForm(reader); } document.Close(); return outputMS.ToArray(); }
The problem is that no file is downloaded at all.
Everything seems to be working properly, I can step through the code all the way through returning the FileContentResult with no problems.
Anyone have any ideas as to what's wrong with the way I'm trying to do this or have a different approach to merging the files?