# Bookmark

This topic describes the steps to add, delete, and modify bookmarks in a Word document using DsWord.

## Content

A bookmark marks a specific location in a document for referencing and assigns a name to that location so that the user can easily navigate to that particular location. DsWord provides you [Bookmark](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Bookmark.html) class which represents a bookmark range in the content. Using DsWord, you can add bookmarks in a document with [Add](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.BookmarkCollection.Add.html) method of the [BookmarkCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.BookmarkCollection.html) class and delete them using [Delete](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Bookmark.Delete.html) method of the **Bookmark** class.
![Bookmark in a Word document](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/bookmark.gif)

## Add Bookmark

To add a bookmark:

1. Define a bookmark.
2. Add a paragraph to be marked by a bookmark.
3. Apply bookmark to the paragraph by adding a bookmark to the bookmark collection using **Add** method of the **BookmarkCollection** class.
4. Add a hyperlink that navigates to the bookmark location on clicking, using the [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("A bookmark marks a specific location" +
        " in a document for referencing and assigns a name to that location so that" +
        " the user can easily navigate to that particular location.");
    
    //Add a paragraph to the section
    for (var pr = 1; pr <= 30; pr++)
    {
        section.GetRange().Paragraphs.Add("Section1: Test Paragraph");
    }
    
    //Define bookmark name
    var bmk = "Bookmark1";
    
    // Add a paragraph
    var pb = section.GetRange().Paragraphs.Add($"{bmk} points here.");
    
    //Mark the paragraph with a bookmark
    pb.GetRange().Bookmarks.Add(bmk);
    
    //Create hyperlink text to jump to the bookmark location(paragraph)
    p.GetRange().Runs.Add("Jump to");
    p.GetRange().Hyperlinks.Add(bmk, $"{bmk}");
    p.GetRange().Runs.Add("at the end of the document.");
    
    //Save the document
    doc.Save("AddBookmark.docx");
    ```

## Modify Bookmark

To modify a bookmark:

1. Access a bookmark to modify from the bookmarks collection using [Bookmarks](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.Bookmarks.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 bookmark.
2. Modify the bookmark name using [Name](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Bookmark.Name.html) property of the **Bookmark** class.
3. Update the bookmark name in the hyperlink created for the bookmark.

    ```csharp
    doc.Load("AddBookmark.docx");
    
    //Modify the bookamrk name
    var newBmk = "TestBookmark";
    Bookmark bmark = 
       doc.Body.Sections.First.GetRange().Paragraphs.Last.GetRange().Bookmarks.First;
    bmark.Name = newBmk;
    
    //Update the bookmark name in the hyperlink created for the bookmark
    Hyperlink hyperlink_bookmark = 
       doc.Body.Sections.First.GetRange().Paragraphs.First.GetRange().Hyperlinks.First;
    hyperlink_bookmark.Anchor = newBmk;
    hyperlink_bookmark.GetRange().Texts[0].Value = newBmk;
    
    //Save the document
    doc.Save("ModifyBookmark.docx");
    ```

## Delete Bookmark

To delete a bookmark, access the bookmark from the bookmark collection using **Bookmarks** property of the **RangeBase** class and delete it using the **Delete** method.

```csharp
//Load the existing word document
doc.Load("AddBookmark.docx");

//Delete bookmark
Bookmark bmark = 
   doc.Body.Sections.First.GetRange().Paragraphs.Last.GetRange().Bookmarks.First;
bmark.Delete();

//Delete hyperlink to bookmark
doc.Body.Sections.First.GetRange().Paragraphs.First.GetRange().Runs[1].Delete();
doc.Body.Sections.First.GetRange().Paragraphs.First.GetRange().Hyperlinks.First.Delete();
doc.Body.Sections.First.GetRange().Paragraphs.First.GetRange().Runs.Last.Delete();

//Save the document
doc.Save("DeleteBookmark.docx");
```

For more information on how to implement bookmarks using DsWord, see [DsWord sample browser](https://developer.mescius.com/documents-api-word/demos/).