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

本文关键字:集中 程序集 文件 添加 程序 单独 何访问 访问 | 更新日期: 2023-09-27 18:28:54

我有一个项目,我把我的报告文件放在其中,现在我想在另一个项目中重新引用它们,我尝试了以下代码:

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

我认为这是因为报告是作为内容而不是资源添加到项目中的。知道吗?

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

您应该尝试相对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);