I have an object called ReportRepository that stores the generated report in a database. I would like to give users the ability to view these reports, so I pull the data back into an array of bytes. Below is a snippet of the logic code that I use to save the report and view the report. When I try to load a report in the second method, the page throws the following exception: "Unsupported operation. A document processed by the JRC mechanism cannot be opened on the C ++ stack." I just want to view my saved reports, what is the right way to do this?
Edit: I would also like to add that I changed the first method to ExportToHTTPResponse instead of exporting to Stream to make sure that the report is actually generated in the browser properly. I can confirm that it is being generated, and Chrome is viewing PDF well.
public static void GenerateReport() { ReportDocument report = new ReportDocument(); string strRptPath = System.Web.HttpContext.Current.Server.MapPath("~/") + "Reports//" + "ProgressReport.rpt"; report.Load(strRptPath); report.VerifyDatabase(); Stream pdfStream = report.ExportToStream(ExportFormatType.PortableDocFormat); byte[] arr = new byte[pdfStream.Length]; pdfStream.Read(arr, 0, (int)pdfStream.Length); ReportModel model = new ReportModel(); model.ReportData = arr; model.ReportName = "TestReport"; ReportRepository repo = new ReportRepository(); repo.AddReport(model); } public static void ViewStoredReport(string id) { ReportDocument report = new ReportDocument(); ReportModel model = new ReportModel(); ReportRepository repo = new ReportRepository(); model = repo.LoadReport(id); string strRptPath = System.Web.HttpContext.Current.Server.MapPath("~/") + "Reports//" + "ProgressReport.rpt"; FileStream oFileStream = new FileStream(strRptPath, FileMode.Create); oFileStream.Write(model.ReportData, 0, model.ReportData.Length); oFileStream.Close(); oFileStream.Dispose(); report.Load(strRptPath); report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, null, false, "progressreport"); }
source share