【发布时间】:2013-11-08 13:23:20
【问题描述】:
这是我第一次这样做。
我已经构建了一个软件。我将使用 Visual Studio 中的安装程序包。我想我将使用为基于 Windows 的应用程序构建安装程序的安装项目,因为我的项目是在窗口窗体上构建的。我已经包括了水晶报表。就目前而言,当用户单击显示报告的按钮时,我的应用程序中有方法。在该方法中,.rpt 文件路径显示为....
cryRpt.Load("C:\\MyFolder\\MyFolder\\ProjectName\\FolderName\\HRMS\\HRMS\\Report.rpt"); // this is from my PC.
所以我的问题是我需要知道什么来设置正确的 .rpt 文件路径。它将安装在哪里?
为了澄清,我需要在客户端 PC 上安装 Crystal Reports 吗? http://downloads.businessobjects.com/akdlm/cr4vs2010/CRforVS_13_0.exe
因为我看了这个帖子...here
我需要在客户的 PC 上做其他事情吗?
我不确定我是否会遇到与此线程相关的问题here 我对路径进行了硬编码,有什么建议吗?
如果有人可以在这里帮助我,请提前感谢您。
using CrystalDecisions.CrystalReports.Engine;
private void btnReportA_Click_1(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("C:\\MyFolder\\MyFolder\\ProjectName\\FolderName\\HRMS\\HRMS\\Report.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
myCon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\MyFolder\MyFolder\ProjectName\FolderName\database.mdb");
crystalReportViewer1.Refresh();
}
使用解决方案更新 1
我看了水晶报表动态路径,我从这行代码改...
cryRpt.Load("C:\\MyFolder\\MyFolder\\ProjectName\\FolderName\\HRMS\\HRMS\\Report.rpt");
到
cryRpt.Load(Application.StartupPath + "\\Report.rpt");
然后移动bin\Debug中的rpt文件
您可以使用以下代码找到您的 bin/Debug 文件位置...
TextBox1.Text = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly
().Location);
我从这个网站得到的。
我认为以上是一个解决方案。
每当我发现如何将安装项目与 Crystal Reports 一起使用时,我都会提供更新 2,因为我可能需要也可能不需要在客户的 PC 上进行更新。
花了几个小时才弄明白。
更新 2 我将打开一个新线程。我认为更新 1 并不是真正的解决方案。
【问题讨论】:
标签: c# winforms ms-access crystal-reports