none
space inside Internal hyperlink fieldcode text RRS feed

  • Question

  • Hello,

    We have a application where we have to count the length of the fieldcode text in word document for which we are counting the text inside the InstrText tag which is working fine so far. But we are not able to calculate the fieldcode text of the internal hyperlink field. we using below code snippet to manually build instrText of the hyperlink field.

    string HyperlinkFC = string.Empty;
    if (element.Attributes().Any(a => a.Name.LocalName == “anchor”))
    {
    string s = @”HYPERLINK \l”; 
    HyperlinkFC = string.Format(” {0} \”{1}\” “, s, element.Attribute(W.anchor).Value);
    }
    fieldCodeText.Append(HyperlinkFC);

    Above code is working fine for some cases like below:
    {HYPERLINK \l “_Toc165886552”}

    But it is failing for some cases where there is a trailing and leading white space inside the curly braces of Hyperlink fieldcode in the begining and end as below

    { HYPERLINK \l “_Toc165886552” }

    It is giving 2 characters length difference than expected.

    Any help will be truly appreiciated!!

    Thanks
    Wednesday, January 11, 2017 5:12 PM

All replies

  • Hi,

    I think we could not retrieve hyperlink field code using Open XML library.  I failed to find the code info when checking the xml nodes of the document. So we are unable to check if there is space inside the hyperlink fieldcode.

    I would suggest you directly retrieve the value like “_Toc165886552”.

    Regards,

    Celeste


    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.

    Friday, January 13, 2017 6:37 AM
    Moderator
  • so are you saying there is no way to find out  the space in HYPERLINK field code  in openxml sdk?

    We need full hyperlink fieldcode to match the exact length that's why we were building it using above code snippet.

    Friday, January 13, 2017 11:19 AM
  • Yes. I think it is impossible to find the space in the hyperlink field code using Open XML Library.

    If using Word Interop is optional, I suggest you use Word Automation or Word Add-in. Please visit Field.Code property


    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 16, 2017 7:25 AM
    Moderator