1
我想将.xps文档加载到我的WPF应用程序中的DocumentViewer对象中。一切工作正常,除非我尝试加载资源.xps文档。我可以在使用绝对路径时加载.xps文档,但是当我尝试加载资源文档时,它会抛出“DirectoryNotFoundException”.NET WPF应用程序:加载资源.XPS文档
下面是加载文档的代码示例。
using System.Windows.Xps.Packaging;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//Absolute Path works (below)
//var xpsDocument = new XpsDocument(@"C:\Users\..\Visual Studio 2008\Projects\MyProject\MyProject\Docs\MyDocument.xps", FileAccess.Read);
//Resource Path doesn't work (below)
var xpsDocument = new XpsDocument(@"\MyProject;component/Docs/Mydocument.xps", FileAccess.Read);
DocumentViewer.Document = xpsDocument.GetFixedDocumentSequence();
}
当DirectoryNotFoundException被抛出,它说:“找不到路径的一部分:‘C:\ MyProject的;组件\文档\ MyDocument.xps’
看来,它正试图从道路抢.XPS文件,就好像它是计算机上的实际路径,而不是试图从存储的应用程序中的资源.XPS抢。
即使做了上面列出的内容,看起来它仍然试图读取作为实际路径放入参数的任何字符串。例如,我在参数中放入了@“Docs/Mydocument.xps”,并且因为它正在查看C:\ docs \ mydocument.xps路径而引发错误。 – contactmatt 2010-06-06 03:05:21
我在编辑我的帖子后,意识到'XpsDocument' ctor接受文件路径,而不是URI。 – repka 2010-06-07 14:40:33
我再次编辑它添加与包裹捣毁。丑,但它的作品。 – repka 2010-06-07 15:07:42