c# - 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;
}
}
谢谢。
解决方案
好吧,报告定义只是一个 XML,所以从哪里获取它并不重要。查看代码我认为它不起作用,因为您有一个文件,但是在设置 IdentifierType 时使用的是 TypeReportSource 而不是 UriReportSource。
在这种情况下,我认为您应该使用 CustomReportSource。IdentifierType可以是 TypeReportSource、UriReportSource 和 CustomReportSource 。前两个不适用于您的情况,因为您不知道报告类型并且您也不想将其保存到文件中。CustomReportSource 将允许您放置自己的逻辑,该逻辑将从数据库中获取报告并将其发送到引擎。实际上有一篇文档文章完全适合您的场景: How to Implement a Custom Report Source Resolver
推荐阅读
- fish - 鱼中的pyenv:未知命令:pyenv
- python - 如何在pylint中做出一些警告是必须的?
- javascript - 如何在使用 The Final Countdown 插件时进行时区调整?
- mysql - 如何获得上周、月份排名从一个到多个表
- python - 写端关闭后,为什么在 FIFO 中继续读?
- java - OpenJDK Java 17 泊坞窗图像
- php - 用户 ID 模块 - 哈希电子邮件地址
- node.js - NPM 安装
- python - 使用 quicksum 的 Gurubi python 约束
- python-3.x - Mac 上的 Python3 和 PySDL2:没有名为“sdl2.util”的模块