Documents for Word .NET Edition
Features / Links / Hyperlink
In This Topic
    Hyperlink
    In This Topic

    GcWord allows you to add, modify, and delete hyperlinks in a document. In GcWord, hyperlink element is represented by the Hyperlink class. You can add a hyperlink in a document using Add method of the HyperlinkCollection class. It can also be modified using the Hyperlink class properties, and deleted using Delete method of the ContentObject class.

    Hyperlink in a Word document

    Add Hyperlink

    To add a hyperlink in a document:

    1. Access a section in a document where the hyperlink is to be added.
    2. Add a paragraph to the section using Add method of the ParagraphCollection class.
    3. Add a hyperlink to the paragraph using Add method of the HyperlinkCollection class.
      C#
      Copy Code
      var section = doc.Body.Sections.First;
      
      //Add the first paragraph          
      var p = section.GetRange().Paragraphs.Add(
          "Among other things, fields allow to insert hyperlinks into documents." +
          " Following is a hyperlink to a web address. ");
      
      //Add a hyperlink to it
      Hyperlink link1 = p.GetRange().Hyperlinks.Add(new Uri("http://www.google.com"),
                        "", "Click to go to www.google.com.");
      
      //Save the document
      doc.Save("AddHyperlink.docx");
         
    Back to Top

    Modify Hyperlink

    To modify a hyperlink:

    1. Access a hyperlink from the hyperlink collection using Hyperlinks property of the RangeBase class. For example, access the first hyperlink of the collection.
    2. Modify the address for the specified link using Address property of the Hyperlink class.
    3. Modify the text content value for the link using Value property of the Text class.
      C#
      Copy Code
      //Load the existing word document in GcWord instance
      doc.Load("AddHyperlink.docx");
      
      //Modify the hyperlink code
      Hyperlink link1 = 
          doc.Body.Sections.First.GetRange().Paragraphs.First.GetRange().Hyperlinks.First;
      link1.Address = new Uri("http://www.grapecity.com");
      link1.GetRange().Texts[0].Value = "Click to visit Grapecity website";
      
      //Save the document
      doc.Save("ModifyHyperlink.docx");
           
    Back to Top

    Delete Hyperlink

    To delete a hyperlink:

    1. Access a hyperlink from the hyperlink collection using Hyperlinks property of the RangeBase class. For example, access the first hyperlink of the collection.
    2. Delete the field using the Delete method of the ContentObject class.
      C#
      Copy Code
      //Load the existing word document in GcWord instance
      doc.Load("AddHyperlink.docx");
      
      //Delete hyperlink to bookmark 
      doc.Body.Sections.First.GetRange().Paragraphs.First.GetRange().Hyperlinks.First.Delete();
      
      //Save the document
      doc.Save("DeleteHyperlink.docx");
    Back to Top

    For more information on how to implement hyperlinks using GcWord, see GcWord sample browser.