如何访问已在单独的程序集中添加为内容的文件?

时间:2013-08-24 04:40:46

标签: c#

我有一个项目,我将我的报告文件放入其中,现在我想在另一个项目中引用它们,我尝试了这段代码:

StiReport.Load(new Uri("pack://application:,,,/GoldAccountingSystem.Reports;component/StimulReports/TBank.mrt")
                    .LocalPath);  

但是我收到了这个错误:

Could not find a part of the path 'E:\GoldAccountingSystem.Reports;component\StimulReports\TBank.mrt'.

GoldAccountingSystem.Reports是报告的程序集名称,但我不知道为什么它会在E中查找此程序集,尽管正确的地址为E:\Projects\GoldAccountingSystem\GoldAccountingSystem.Reports

我认为这是因为报告作为内容而不是资源添加到项目中。任何想法?

1 个答案:

答案 0 :(得分:0)

你应该尝试相对Uri:

StiReport.Load(new Uri("/GoldAccountingSystem.Reports;component/StimulReports/TBank.mrt")
                    .LocalPath);

绝对的Uri也应该有效:

StiReport.Load(new Uri("pack://application:,,,/GoldAccountingSystem.Reports;component/StimulReports/TBank.mrt", UriKind.Absolute)
                    .LocalPath);