none
Hyperlinks in Word seem to be too long RRS feed

  • Question

  • Hi!

    My code, an Application Add-In, is setting relative hyperlinks (to PDF files) in Word files. For instance:

    • C:\FolderA contains Doc1.docx.
    • C:\FolderA\FolderB contains LinkedFile.pdf
    • The hyperlink address set in Doc1.docx is "FolderB\LinkedFile.pdf"

    On mouse over, the StatusBar does not show the relative, but the absolute hyperlink, and in UNC, not the mapped drive. So I assume that is the determining length to be considered.

    Hyperlinks up to 258 characters long (UNC length) work both in Word as well as in IE.

    One character longer, and I’m getting following errors when following the link:

    • Word 2010 and 2013: “An unexpected error has occurred.”
    • Word 2016: “Cannot locate the Internet server or proxy server.”
    • When I’m opening a PDF with this UNC through IE, it works fine as long as its length is <= 258 characters. One character longer, and the PDF does not open (no error message, IE just does not react).

    I also noticed that the 259 character-hyperlinks do work when the text to display is the same as the address.

    Now I plan to check the hyperlink length before setting the link, in order to avoid later difficulties. Before I’m making the wrong assumptions:

    1. Which length determines the maximum length of a hyperlink? Is it really the UNC? Or is it another value? (I’m kind of skeptical because the “ok-UNC” is 258 characters long, not 256. But maybe that is because of the backslashes?)
    2. If it is the UNC: How do I get the UNC of the linked file at runtime in order to count its characters?

    Any suggestion is highly appreciated.

    Thanks and kind regards

    Nora

    Saturday, January 7, 2017 1:15 PM

All replies

  • Hi nora.sailer,

    The limit of UNC is 32 K Characters.

    Use the \\?\ UNC prefix to break out of "DOS mode" for paths.

    The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".

    Reference:

    C#: Any way to get around the 260 character limit of a fully qualified path?

    Naming Files, Paths, and Namespaces

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 9, 2017 1:43 AM
    Moderator
  • Hi Deepak Panchal10,

    Thanks for your help.

    Word does not allow me to manually save a hyperlink address beginning with "\\?".

    So I first tried to enter three different kinds of paths both in IE as well as in the file explorer with the UNC prefix according to https://en.wikipedia.org/wiki/Path_%28computing%29, in order to find out the right syntax before "blindly" coding it: Once with the drive letter, once with the servername, and once with the IP address. In all three cases, the file was not found (but is found when I'm addressing it with  "\\servername\..." or "\\IP address\...").

    Does the UNC prefix work in IE and the file explorer at all?

    For a start, I would be happy if there is a way to know which kind of path Word is considering to be too long (path with mapped drive letter? With IP address? With Servername? With some prefixes like "file:" or without any prefixes?). I then could check on the path length during runtime and warn the users, that this hyperlink won't do.

    Kind regards

    Nora

    Wednesday, January 11, 2017 3:12 PM
  • Hi nora.sailer,

    I try to find the limitation of word in path length.

    but I did not find any useful documentation on that.

    in the below document they have mentioned some limitations but there is nothing about path length.

    Operating parameter limitations and specifications in Word

    I will try to find further. if get something useful then I will provide you.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 12, 2017 6:34 AM
    Moderator
  • Hi Deepak Panchal10

    Thanks for your reply. The limitations you found are useful anyway, even though for other purposes.

    For the time being, I might go for the URI (something like string uri = new Uri(file.FullName).AbsoluteUri;) and only allow hyperlink addresses with URIs shorter than or equal to 256, just to be on the safe side.

    But of course I'd rather find out what is what instead of guessing.

    Kind regards

    Nora

    Saturday, January 14, 2017 3:17 PM
  • Hi nora.sailer,

    in your last post you was describing to use  URI .

    does that approach solved your issue?

    if yes, then please try to update the status of this thread.

    so that we can try to close this thread.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 25, 2017 7:54 AM
    Moderator
  • Hi Deepak

    I'd like to apologize for my long not answering (due to other projects). I still don't know if this will solve the problem. I'll keep you and this thread informed as soon as I know more.

    Kind regards

    Nora

    Saturday, March 25, 2017 11:59 AM