locked
Add hyperlink RRS feed

  • Question

  • ok seriously this is the 4th day in a row that ive asked a question, but ive been googling and searching the sdk documentation and cant find out how to do this.

     

    I know what markup is required to add a hyperlink.

     

    I have this in the document

    Code Snippet

    test@domain.com

     

     

    And I need something like this in the document.xml.rels file

     

    Code Snippet

    <Relationship Id=""rId4"" Type=""http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"" Target=""mailto:test@domain.com"" TargetMode=""External"" />

     

     

    Now how do I get the markup into the document.xml.rels file.  It looks like the rels file is generated by the packaging class and you just need to add a new document part.  I didnt see any relationship part or hyperlink part.
    Thursday, July 24, 2008 8:53 PM

Answers

  • The best thing about OpenXml SDK is encapsulation over the Packaging API, In the old days (I mean before the OpenXml SDK days Smile ) we had get a handle of the Package and Parts (using WindowsBase) and then we had relationship classes to create all the required relationships, not anymore my friend Smile

     

    Here is how you can insert a Hyperlink

     

    Hyperlinks can actually be creaeted using ExternalRelationship

     

    ExternalRelationship _newExternalRels = mainDocumentPart.AddExternalRelationship(relationship.Value.RelationshipType,

    relationship.Value.Uri);

     

    The only thing you have to do after this is add an hyperlink element in your document.xml where you want to insert this link

    you can get the id from _newExternalRels.Id;

     

    <w:hyperlink r:id="<<UpdateId here>>" w:history="1">

    <w:r>

    <w:rPr>

    <w:rStyle w:val="Hyperlink" />

    </w:rPr>

    <w:t>test@domain.com</w:t>

    </w:r>

    </w:hyperlink>

     

     

     

    Hope this helps

     

    Friday, July 25, 2008 6:18 AM

All replies

  • The best thing about OpenXml SDK is encapsulation over the Packaging API, In the old days (I mean before the OpenXml SDK days Smile ) we had get a handle of the Package and Parts (using WindowsBase) and then we had relationship classes to create all the required relationships, not anymore my friend Smile

     

    Here is how you can insert a Hyperlink

     

    Hyperlinks can actually be creaeted using ExternalRelationship

     

    ExternalRelationship _newExternalRels = mainDocumentPart.AddExternalRelationship(relationship.Value.RelationshipType,

    relationship.Value.Uri);

     

    The only thing you have to do after this is add an hyperlink element in your document.xml where you want to insert this link

    you can get the id from _newExternalRels.Id;

     

    <w:hyperlink r:id="<<UpdateId here>>" w:history="1">

    <w:r>

    <w:rPr>

    <w:rStyle w:val="Hyperlink" />

    </w:rPr>

    <w:t>test@domain.com</w:t>

    </w:r>

    </w:hyperlink>

     

     

     

    Hope this helps

     

    Friday, July 25, 2008 6:18 AM
  • good ol sdk to the rescue,  thanks.

    Friday, July 25, 2008 1:08 PM
  • In Open XML SDK 2.5 you need to use AddHyperlinkRelationship.
    Friday, April 1, 2016 3:21 PM