Hi All
I have an XPS file converted from an Word document. It contains internal links (anchors). I have also a client WPF application that retrieves XPS document(as Stream object) from the Web Service and than uses provided stream to create XpsDocument object and
displays it in DocumentViewer control. The problem is that hyperlinks(anchors) do not work properly - I've got the UriFormatException exception ("Invalid URI: The format of the URI could not be determined") when trying to open a hyperlink.
I use the following code to open the document in DocumentViewer control (stream is a given parameter...):
string inMemoryPackageName = "memoryStream://ecofinlex";
packageUri = new Uri(inMemoryPackageName,UriKind.Absolute);
Package package = Package.Open(stream, FileMode.Open);
PackageStore.AddPackage(packageUri, package);
xpsDoc = new XpsDocument(package, CompressionOption.Normal, inMemoryPackageName);
docView.Document = xpsDoc.GetFixedDocumentSequence();
I subscribed to the Hyperlink's RequestNavigateEvent event and than investigated the Uri of the hypelink that causes the exception. The Uri is the following "pack://pack:,,ecofinlex,/FixedDocSeq.fdseq#PG_2_LNK_1" and it causes the UriFormatException exception.
The intresting thing is that when I form the XpsDocument directly from the file (the same file that is passed through Web Service call) the exception is not thrown.
xpsDoc = new XpsDocument(@"D:\HappyNewYear.xps", FileAccess.Read);
In this case the uri path in the RequestNavigateEvent handler is the following "pack://file:,,,D:,
HappyNewYear.xps/FixedDocSeq.fdseq#PG_2_LNK_1" and it works fine.
Could you please help me with this problem as I have to load XpsDocument from the stream using Package and have to have all hyperlinks working properly.
Thanks, Sergey
Prosto