Add Bookmark in Word with NET REST API

This tutorial shows you how to add a bookmark in a Word document using the .NET REST API with the Aspose.Words for .NET Cloud SDK. You’ll learn to configure bookmark properties and make the necessary API calls from C# low‑code, applying the bookmark to a Word file stored on your local disk.

Prerequisite

Steps to Create Bookmark in Word with NET REST API

  1. Set Client ID and Client Secret for the API to add a bookmark
  2. Instantiate an object of the WordsApi class with your client credentials
  3. Read the source Word file into the memory stream for creating a bookmark
  4. Define the start and end range of the bookmark using the PositionInsideNode class
  5. Create the InsertBookmarkOnlineRequest object by providing the required parameters
  6. Call the InsertBookmarkOnline method to insert a bookmark according to the InsertBookmarkOnlineRequest
  7. Save the resultant Word file with the new bookmark

The aforementioned steps describe how to create a bookmark in Word with C# Low Code API. Commence the process by creating a WordsApi object followed by reading the source Word file and defining the bookmark parameters. Finally, add this bookmark to your Word file by calling a few API calls followed by saving the resultant Word file on the local disk.

Code to Insert a Bookmark in Word with C# REST API

Here’s a concise example that demonstrates how to add a bookmark in Word using the C# REST API. By employing the PositionInsideNode class, you specify the bookmark’s start and end ranges within the target Word file. The resulting stream is placed into a dictionary under the chosen key, and you can retrieve it with the TryGetValue method exactly as shown in the sample code.

In this tutorial you’ve learned how to make a bookmark in Word with C# REST API. Want to go further? Check out our guide on converting a Word document to HTML at Convert DOCX to HTML with NET REST API.

 English