如何从MVC 4中的数据库加载Crystal Report?

时间:2012-12-07 04:33:26

标签: asp.net-mvc crystal-reports

我有一个名为ReportRepository的对象,它将生成的报告存储到数据库中。我想让用户能够查看这些报告,因此我将数据拉回到一个字节数组中。下面是我用来保存报告和查看报告的逻辑的代码片段。当我尝试在第二种方法中加载报表时,该页面抛出以下异常:“不支持的操作。无法在C ++堆栈中打开由JRC引擎处理的文档。”我只是想查看我存储的报告,这是做什么的正确方法?

编辑:我还想补充一点,我已经将第一个方法更改为ExportToHTTPResponse而不是导出到Stream只是为了确保报告实际上是在浏览器中正确生成的。我可以确认它正在生成,Chrome浏览器就可以了。

        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");
    }

0 个答案:

没有答案