8

I am having a trouble adding hyperlinks to my word document. I don't know how to do it. I would like to make a link in a word document from my C# code using open xml. Is ther a different solution using only href or sth similar? There is a HyperLink class on the net from Open XML but how to use it?

Antun Tun
  • 1,507
  • 5
  • 20
  • 38
  • Maybe this will help http://blogs.catapultsystems.com/jdunagan/archive/2011/04/21/add-hyperlinks-to-a-word-document-with-open-xml.aspx – Khurshid Apr 18 '13 at 14:35

1 Answers1

12

Try this

using (WordprocessingDocument doc = WordprocessingDocument.Open("", true))
{
    doc.MainDocumentPart.Document.Body.AppendChild(
        new Paragraph(
            new Hyperlink(new Run(new Text("Click here")))
            {
                 Anchor = "Description",
                 DocLocation = "location",
             }
        )
    );

    doc.MainDocumentPart.Document.Save();

}
Joe
  • 15,205
  • 8
  • 49
  • 56
Khurshid
  • 954
  • 7
  • 19