繁体   English   中英

如何调整wpf应用程序在另一台PC上的XPS文档的路径?

[英]How to adjust path of XPS document for wpf Application to work on another PC?

我有一个简单的wpf应用程序,其中包含一个带有文档查看器的窗口,用于显示XPS文档。

 XpsDocument myDoc = new XpsDocument(@"C:\Users\Ahmad
 Elsayed\Desktop\testxpsdoc\xpsTest\xpsTest\Assets\Dokhna - Problems -
 Report.xps", FileAccess.Read);

 DV.Document = myDoc.GetFixedDocumentSequence();

但是问题是,当我发布应用程序并在另一台PC上使用时,我得到了:

System.IO.DirectoryNotFoundException:找不到路径的一部分

我试图使用这样的相对路径:

XpsDocument myDoc = new XpsDocument(@"\Assets\Dokhna - Problems - Report.xps", FileAccess.Read);

但还是一样,因为我将构建操作设置为Content,如果更新则复制到xps文件。

这也是解决方案资源管理器Solution Explorer

您应该获得正在运行的应用程序的基本目录,可以将其附加到XPS文件的相对路径中。 即使您部署了该应用程序,只要您在可执行文件旁边的Assets文件夹中拥有XPS文件,该方法也应该起作用。

string xpsFilePath = Path.Combine(
    AppDomain.CurrentDomain.BaseDirectory,
    @"Assets\Dokhna - Problems - Report.xps");

XpsDocument myDoc = new XpsDocument(xpsFilePath, FileAccess.Read);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM