# Hyperlink

Learn how to add, modify, and delete hyperlinks in a Word document using DsWord.

## Content

DsWord allows you to add, modify, and delete hyperlinks in a document. In DsWord, hyperlink element is represented by the [Hyperlink](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Hyperlink.html) class. You can add a hyperlink in a document using [Add](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.HyperlinkCollection.Add.html) method of the [HyperlinkCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.HyperlinkCollection.html) class. It can also be modified using the **Hyperlink** class properties, and deleted using [Delete](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentObject.Delete.html) method of the [ContentObject](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentObject.html) class.
![Hyperlink in a Word document](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/hyperlink.png)

## 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](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ParagraphCollection.Add.html) method of the [ParagraphCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ParagraphCollection.html) class.
3. Add a hyperlink to the paragraph using [Add](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.HyperlinkCollection.Add.html) method of the [HyperlinkCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.HyperlinkCollection.html) class.

    ```csharp
    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");
    ```

## Modify Hyperlink

To modify a hyperlink:

1. Access a hyperlink from the hyperlink collection using [Hyperlinks](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.Hyperlinks.html) property of the [RangeBase](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.html) class. For example, access the first hyperlink of the collection.
2. Modify the address for the specified link using [Address](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Hyperlink.Address.html) property of the [Hyperlink](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Hyperlink.html) class.
3. Modify the text content value for the link using [Value](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Text.Value.html) property of the [Text](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Text.html) class.

    ```csharp
    //Load the existing word document
    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://developer.mescius.com");
    link1.GetRange().Texts[0].Value = "Click to visit MESCIUS, Inc. website";
    
    //Save the document
    doc.Save("ModifyHyperlink.docx");
    ```

## 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](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentObject.Delete.html) method of the [ContentObject](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentObject.html) class.

    ```csharp
    //Load the existing word document
    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");
    ```
For more information on how to implement hyperlinks using DsWord, see [DsWord sample browser](https://developer.mescius.com/documents-api-word/demos/basics/content/hyperlinks/code-cs).