ReportViewer:如何使用反射将报表作为嵌入资源加载到另一个程序集中?

发布于 2024-09-28 04:21:59 字数 254 浏览 2 评论 0原文

我不太确定该怎么做。我创建了一个通用类来为我的应用程序打开报告。这些报告包含在另一个 DLL 中,但该 DLL 并未作为嵌入式资源引用。

如果我引用 DLL,我可以这样做:
Viewer.LocalReport.ReportEmbeddedResource = "SomeLibrary.ReportName.rdlc";

但是,由于我没有引用 DLL,我认为我必须通过反射获取报告。这就是我被困住的地方。我真的不知道该怎么做。

I'm not really sure how to go about this. I created a generic class to open reports up for my application. The reports are contained in another DLL that is not referenced as an embedded resource though.

If I reference the DLL I can just do:
Viewer.LocalReport.ReportEmbeddedResource = "SomeLibrary.ReportName.rdlc";

However, since I'm not referencing the DLL I figure I have to get the report via reflection. This is where I'm stuck. I'm really not sure how to go about this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在夏天 2024-10-05 04:21:59

我找到了一种通过读取 RDLC 并返回 Stream 来做到这一点的方法。

public void PrepareReport(IAppReport report)
{
   Viewer.LocalReport.LoadReportDefinition(report.GetStream());
}

经过一些思考,我能够拉出该 Stream 对象。

I found a way to do this by reading the RDLC and returning the Stream.

public void PrepareReport(IAppReport report)
{
   Viewer.LocalReport.LoadReportDefinition(report.GetStream());
}

With a bit of reflection I am able to pull that Stream object.

憧憬巴黎街头的黎明 2024-10-05 04:21:59
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream streamReport = assembly.GetManifestResourceStream("MyProjectOrAssemblyName.Reports.Report1.rdlc");

reportView1.ProcessingMode = ProcessingMode.Local;
reportView1.LocalReport.LoadReportDefinition(streamReport);
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream streamReport = assembly.GetManifestResourceStream("MyProjectOrAssemblyName.Reports.Report1.rdlc");

reportView1.ProcessingMode = ProcessingMode.Local;
reportView1.LocalReport.LoadReportDefinition(streamReport);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文