首页 > 解决方案 > Telerik - 我可以从数据库加载报告定义吗

问题描述

我正在开发一个 WebApplication,并在其中包含一个Telerik-Report。所描述的正常方式效果很好。

现在我正在尝试从数据库加载报告定义,而不是拥有一个文件(来自老板的请求)。到目前为止,我已经使它与一个临时文件一起工作,代码如下。但这远非良好的编码。

我的问题:我可以以某种方式为报告(而不是文件)提供字符串或流吗?

我当前的代码如下所示:

private readonly string __path = "C:\\my-temp-directory\\Reports\\";
protected void Page_Load(object sender, EventArgs e) {
    string contents =  /** Get XML from Database **/;
    File.WriteAllText(__path + "temp.trdx", contents);   // <-- This file I want to omit.
    if (!IsPostBack) {
        this.reportViewer1.ReportSource.Identifier = "temp.trdx";
        this.reportViewer1.ReportSource.IdentifierType = IdentifierType.TypeReportSource;
    }
}

谢谢。

标签: c#teleriktelerik-reporting

解决方案


好吧,报告定义只是一个 XML,所以从哪里获取它并不重要。查看代码我认为它不起作用,因为您有一个文件,但是在设置 IdentifierType 时使用的是 TypeReportSource 而不是 UriReportSource。

在这种情况下,我认为您应该使用 CustomReportSource。IdentifierType可以是 TypeReportSource、UriReportSource 和 CustomReportSource 。前两个不适用于您的情况,因为您不知道报告类型并且您也不想将其保存到文件中。CustomReportSource 将允许您放置自己的逻辑,该逻辑将从数据库中获取报告并将其发送到引擎。实际上有一篇文档文章完全适合您的场景: How to Implement a Custom Report Source Resolver


推荐阅读