构建设置后的工作报告 [英] work reports after build setup
问题描述
我想知道如何在c#中为不同的机器名称创建Crystal报表.
ReportDocument cryRpt =新的ReportDocument();
cryRpt.Load(@"C:\ Documents and Settings \ Arusha \ My Documents \ Visual Studio 2008 \ Projects \ Schooll工资系统\ Schooll工资系统\ rpt_empdataall.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
这里的阿鲁沙"是我的比赛名称,也是位置c的路径:在另一台机器上是不同的,因此在安装另一台机器后我无法获得报告.请给我解决方案.
i want to know how to create crystal report for different machine names in c#
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(@"C:\Documents and Settings\Arusha\My Documents\Visual Studio 2008\Projects\Schooll salary system\Schooll salary system\rpt_empdataall.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
here "Arusha" is my matchine name and also path of location c: is different for onother machine so i can''t genarate reports after intalling another machine. plz give me solution for this.
推荐答案
这很简单.您的错误是您在硬编码绝对路径.使用相对路径.将水晶报表放在应用程序文件夹中,然后使用该文件夹的相对路径进行访问.这样,无论您在哪里安装了应用程序,Crystal Reports都将以固定的路径传递并可以访问.
It''s pretty simple. Your mistake is that you are hard-coding an absolute path. Use relative path. Put the crystal report in the application folder and then access it using relative path of that folder. This way, where-ever you have your application installed, the crystal report too would be delivered at a fixed path and thus accessible.
使用相对路径.例如
Use relative paths. For instance
string myBasePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
将此设为地面0,并找到与此路径相关的其他来源.
如果报告位于可执行文件旁边的名为"Reports"的目录中,则
您只能使用
Take this as ground 0 and find other sources relative to this path.
If a report is in a directory named "Reports" next to your executable then
you can just use
myBasePath+"\\Reports\\rpt_empdataall.rpt"
,因为报告位于可执行文件
in your case since report is located 2 level above executable
myBasePath+"\\..\\..\\rpt_empdataall.rpt"
的上方2级就足够了.
我希望这是您要实现的目标.
would suffice.
I hope that is what you are trying to achieve.
这篇关于构建设置后的工作报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!