Telerik - 我可以从数据库加载报告定义吗

Telerik - Can I load a report definition from Database

我正在开发 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;
    }
}

谢谢。

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

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