【问题标题】:Crystal report method not found找不到水晶报表方法
【发布时间】:2017-05-16 07:16:35
【问题描述】:

我做了一个反馈项目。我是在 ASP.NET MVC 5 上制作的,它也有水晶报告。报告工作正常,但突然停止工作。我不知道他们发生了什么。但自上周以来,我一直在努力寻找解决方案,但不幸的是找不到合适的解决方案。我下载了不同的运行时间,但都是徒劳的。这是错误的底线。

“找不到方法:'CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag CrystalDecisions.ReportAppServer.ReportDefModel.ISCRExportOptions.get_ExportOptionsEx()'” 这是代码:

public CrystalReportFeedback UserFeedbackDateWise(FeedbackReport be){

        if (Session["CurrentUser"] != null && Convert.ToInt32(Session["User_Id"]) != 0)
        {
            string reportPath = Path.Combine(Server.MapPath("~/Reports"), "UserFeedbackReport.rpt");
            if (ModelState.IsValid)
            {
                be.FromDate = Convert.ToDateTime(TempData["UserFromDate"]);
                be.ToDate = Convert.ToDateTime(TempData["UserToDate"]);
                be.User_Id = Convert.ToInt32(Session["User_Id"]);
            }
            return new CrystalReportFeedback(reportPath, be);
        }
        else
        {
            return null;
            //new CrystalReportFeedback(reportPath, be);
        }
    }

报告的初始化:

public CrystalReportFeedback(string reportPath, FeedbackReport be)//, object dataSet)
        {
            //int[] array;
            string strConnect = Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["TSC"]);
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(strConnect);
            string _username = builder.UserID;
            string _pass = builder.Password;
            string _server = builder.DataSource;
            string _database = builder.InitialCatalog;
            ReportDocument reportDocument = new ReportDocument();
            //
            reportDocument.Load(reportPath);
            reportDocument.SetDatabaseLogon(_username, _pass, _server, _database);
            if (be.Region_Id != 0)
            {
                reportDocument.SetParameterValue("@Region_Id", be.Region_Id);
            }
            if (be.User_Id != 0)
            {
                reportDocument.SetParameterValue("@User_Id", be.User_Id);
            }
            reportDocument.SetParameterValue("@FromDate", be.FromDate);
            reportDocument.SetParameterValue("@ToDate", be.ToDate);
            //reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\report.pdf");
            _contentBytes = StreamToBytes(reportDocument.ExportToStream(ExportFormatType.PortableDocFormat));
        }

导出方式:

    public override void ExecuteResult(ControllerContext context)
    {

        var response = context.HttpContext.ApplicationInstance.Response;
        response.Clear();
        response.Buffer = false;
        response.ClearContent();
        response.ClearHeaders();
        response.Cache.SetCacheability(HttpCacheability.Public);
        response.ContentType = "application/pdf";

        using (var stream = new MemoryStream(_contentBytes))
        {
            stream.WriteTo(response.OutputStream);
            stream.Flush();
        }
    }

    private static byte[] StreamToBytes(Stream input)
    {
        byte[] buffer = new byte[16 * 1024];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            return ms.ToArray();
        }
    }

希望我能尽快得到我的解决方案。

这是修改后的代码:

[HttpGet]

    public FileResult UserFeedbackDateWise(FeedbackReport be)
    {

        if (Session["CurrentUser"] != null && Convert.ToInt32(Session["User_Id"]) != 0)
        {
            string reportPath = Path.Combine(Server.MapPath("~/Reports"), "UserFeedbackReport.rpt");
            if (ModelState.IsValid)
            {

                be.FromDate = Convert.ToDateTime(TempData["UserFromDate"]);
                be.ToDate = Convert.ToDateTime(TempData["UserToDate"]);
                be.User_Id = Convert.ToInt32(Session["User_Id"]);
            }
            string strConnect = Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["TSC"]);
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(strConnect);
            string _username = builder.UserID;
            string _pass = builder.Password;
            string _server = builder.DataSource;
            string _database = builder.InitialCatalog;
            ReportDocument reportDocument = new ReportDocument();
            //
            reportDocument.Load(reportPath);
            reportDocument.SetDatabaseLogon(_username, _pass, _server, _database);
            if (be.Region_Id != 0)
            {
                reportDocument.SetParameterValue("@Region_Id", be.Region_Id);
            }
            if (be.User_Id != 0)
            {
                reportDocument.SetParameterValue("@User_Id", be.User_Id);
            }
            reportDocument.SetParameterValue("@FromDate", be.FromDate);
            reportDocument.SetParameterValue("@ToDate", be.ToDate);

            Stream stream = reportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

            //Here i have my stream with my pdf report, i just create a new FileStreamResult and return it to my client like that : 
            FileStreamResult myfile = new FileStreamResult(stream, "application/pdf");
            return myfile;
                //new CrystalReportFeedback(reportPath, be);
        }
        else
        {
            return null;
            //new CrystalReportFeedback(reportPath, be);
        }
    }

【问题讨论】:

  • 请提供您加载报告的代码以及导出时的代码,谢谢
  • 先生。 @Furtiro 请看代码
  • 最后一个函数导出报表
  • 您好,您想将水晶报告导出为pdf,从您的控制器到您的客户端?如果这是重点,我在这里没有看到任何水晶报表初始化,你在哪里创建你的报表?
  • string reportPath = Path.Combine(Server.MapPath("~/Reports"), "UserFeedbackReport.rpt"); if (ModelState.IsValid) { be.FromDate = Convert.ToDateTime(TempData["UserFromDate"]); be.ToDate = Convert.ToDateTime(TempData["UserToDate"]); be.User_Id = Convert.ToInt32(Session["User_Id"]); } return new CrystalReportFeedback(reportPath, be); }

标签: asp.net model-view-controller crystal-reports


【解决方案1】:

这不是编码问题,而是运行时问题。水晶运行时的版本或应用程序的位数。

首先要尝试的一件事是升级您的开发版本并确保您在生产中运行相同的版本。详情请见https://apps.support.sap.com/sap/support/knowledge/public/en/2148492

上面写着:

将您的应用程序编译为“X86 模式”或“X64 模式” 在部署机器上安装特定版本的运行时。

即如果应用程序编译为 32 位,则安装 32 位运行时。

【讨论】:

  • 你知道如何查看Visual Studio 2013 的版本吗?因为这是我的官方笔记本电脑,所有东西都已经安装在这台笔记本电脑上。你能指导我吗
  • 是你需要升级的水晶版本。检查 web.config 文件以确定您的应用程序正在运行的版本。您希望在 13.x 范围内,并观看支持包版本。您可以从以下地址下载它们:blogs.sap.com/2016/12/06/…
【解决方案2】:

我会尽力帮助您导出报告,但您的帖子不是很清楚。对于您的下一篇文章,请尝试非常具体并提供尽可能多的信息。

我目前制作了一个 MVC 项目并将一个 Crystalreport 报告从我的控制器导出到我的客户。

我认为您的ExecuteResult 方法可以工作,但是使用httpcontext 是没有用的,Crystalreport 和.NET 提供了一些有用的方法来做同样的事情。 因此,我将向您展示我如何创建和导出我的报告,以便您可以复制/粘贴和修改您的代码。

这是我的控制器方法,从按钮调用:

[HttpGet]
    public FileResult InitReport()
    {
     //I create my report here
     FileImportReport rptH = new FileImportReport();

     // Some configuration on the report, datasource, databaselogon .. etc
     ...
     //

     //Then I export my report to a pdf stream like that :
     Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

     //Here i have my stream with my pdf report, i just create a new FileStreamResult and return it to my client like that : 
     FileStreamResult myfile = new FileStreamResult(stream, "application/pdf");

     return myfile;

    }

我的方法是从一个按钮调用的,但它可以像你想要的那样工作,或者文件可以保存在任何已知的路径中。

您可以测试重现我的代码,在您的CrystalReportFeedback 方法中使用我的代码和您的reportDocument 对象,您不需要使用您的StreamToBytes 方法。

问候,

编辑:与您的错误的有用链接:

Crystal Reports exception in Visual Studio 2013

https://www.arcanadev.com/support/kb/K00000499.aspx

【讨论】:

  • Mr.@Furtiro :'(
  • 哪一行导致这个错误?我用有用的链接编辑了我的答案,如果工作代码不起作用,那可能是 Crystalreport 安装或运行时错误(或者可能是配置错误)
  • 流流 = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);此行显示错误
  • 已解决。有版本问题。非常感谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-08
  • 1970-01-01
  • 1970-01-01
  • 2011-05-01
  • 1970-01-01
相关资源
最近更新 更多