4

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");
    }
tereško
  • 58,060
  • 25
  • 98
  • 150
Sean Lindo
  • 1,387
  • 16
  • 33
  • What is the value of `strRptPath` at this line `report.Load(strRptPath);` in debugger ? – Dejan Janjušević Dec 22 '12 at 11:12
  • Have you reviewed other questions dealing with that exact error message? I'd start with this one: http://stackoverflow.com/a/9846867/173225 as it seems to be the most likely culprit. Others: http://stackoverflow.com/q/11272609/173225 There are a number of threads on the SAP forums, which are not loading for me at the moment (not an unusual situation unfortunately). I'd also suggest not using your web root as the location for writing out temporary files. – Colin Young Jan 24 '13 at 14:23

0 Answers0