在我的winform应用程序中获取rdlc报告的相对路径

Mik*_*lls 8 c# reportviewer localreport relative-path winforms

我将在月末流程中自动从一些报告中创建PDF.我遇到了一个ReportViewer.LocalReport无法找到我的报告的问题.在项目中,报告文件位于"(项目根文件夹)/Reports/report.rdlc"中.

我如何设置,ReportViewer.LocalReport.ReportPath以便我可以参考我的报告文件?我宁愿不设置完整路径,因为我不知道在客户端计算机上安装它将在何处安装.

Han*_*ant 16

使用Application.StartupPath属性,它始终指向EXE所在的目录:

  using System.IO;
  ...

     string exeFolder = Application.StartupPath;
     string reportPath = Path.Combine(exeFolder, @"Reports\report.rdlc");
Run Code Online (Sandbox Code Playgroud)

您需要确保将报告复制到bin\Debug\Reports文件夹中,以便它可以在IDE中运行.在构建后事件中使用xcopy/s/d来获取复制的文件.