【问题标题】:ReportViewer: How to load report as an embeddedresource in another assembly using reflection?ReportViewer:如何使用反射将报表作为嵌入资源加载到另一个程序集中?
【发布时间】:2010-10-18 20:20:18
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# reflection embedded-resource reportviewer2008


    【解决方案1】:

    我通过读取 RDLC 并返回 Stream 找到了一种方法。

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

    稍加思考,我就能拉出那个 Stream 对象。

    【讨论】:

    • 您能否将用于读取报告的代码粘贴为来自 dll 的流
    • 我不知道什么是“IAppReport”,这是一个不好的答案,这是正确的解决方案:System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();流 streamReport = assembly.GetManifestResourceStream("MyProjectOrAssemblyName.Reports.Report1.rdlc"); reportView1.ProcessingMode = ProcessingMode.Local; reportView1.LocalReport.LoadReportDefinition(streamReport);
    【解决方案2】:
    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
    Stream streamReport = assembly.GetManifestResourceStream("MyProjectOrAssemblyName.Reports.Report1.rdlc");
    
    reportView1.ProcessingMode = ProcessingMode.Local;
    reportView1.LocalReport.LoadReportDefinition(streamReport);
    

    【讨论】:

      猜你喜欢
      • 2017-11-27
      • 1970-01-01
      • 2011-10-17
      • 2022-01-11
      • 2010-09-29
      • 1970-01-01
      • 2014-05-04
      • 2013-07-08
      • 2011-05-06
      相关资源
      最近更新 更多