I have an object named ReportRepository that is storing a generated report into a database. I'd like to give users the ability to view these reports so I'm pulling the data back out into a byte array. Below is a code snippet of the logic I'm using to save the report and view the report. When I try to load the report in the second method, the page throws the following exception: "Unsupported Operation. A document processed by the JRC engine cannot be opened in the C++ stack." I just want to view my stored reports, what is the right way to do this?
Edit: I'd also like to add that I've changed the first method to ExportToHTTPResponse instead of exporting to a Stream just to make sure the report was actually generating in the browser properly. I can confirm that it is generating and Chrome views the PDF just fine.
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");
}