Cannot open hyperlinks(anchors) in DocumentViewer control. RRS feed

  • Question

  • 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


    • Moved by Andrew_Zhu Monday, January 3, 2011 2:51 AM (From:.NET 4: Windows Workflow Foundation)
    Thursday, December 30, 2010 11:51 PM

All replies

  • Hello,

            Thank you for your post!  I would suggest posting your question in one of the (Microsoft Office > Microsoft Office Forums > Microsoft Office Word Forums > Creating, Editing, and Formatting Documents) forum located here:  (http://social.answers.microsoft.com/Forums/en/wordcreate/threads).

           Hope that would be helpful.

          Have a great day!

          Thanks & regards,

    Shivendra Pratap Singh Tier 2 Application Support Server and Tools Online Operations Team
    Tuesday, January 4, 2011 6:51 AM
  • Hi Shivendra Pratap Singh,

    Thank you for your reply. I am not sure why this post was moved from WPF (.NET 4). The question is all about how hyperlink works in DocumentViewer WPF control. I just mentioned that XPS document is created from Word document, but I could create XPS from another source document. So the the question is not related to Microsoft Office. At least the issue might be in creating the  "Package" object and forming the package Uri.

    Thanks, Sergey

    Tuesday, January 4, 2011 11:25 AM