This article entails the process to add bookmark in Word with NET REST API. We will use Aspose.Words for .NET Cloud SDK to add bookmark to Word document with C# Low Code API. You will set various bookmark parameters and invoke API calls to add this bookmark to your Word file on the local disk.
Prerequisite
- Create an account and get API credentials
- Download Aspose.Words Cloud SDK for Dotnet to add a bookmark in a Word file
- Setup C# solution project with the above SDK
Steps to Create Bookmark in Word with NET REST API
- Set Client ID and Client Secret for the API to add a bookmark
- Instantiate an object of the WordsApi class with your client credentials
- Read the source Word file into the memory stream for creating a bookmark
- Define the start and end range of the bookmark using the PositionInsideNode class
- Create the InsertBookmarkOnlineRequest object by providing the required parameters
- Call the InsertBookmarkOnline method to insert a bookmark according to the InsertBookmarkOnlineRequest
- 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
This sample code exhibits how to add bookmark in Word with C# REST API. The PositionInsideNode class is used to set the start and end range of the bookmark in the destination Word file. The resultant stream is returned as a dictionary item with the specified key and can be retrieved using the TryGetValue method as demonstrated in the sample code.
In this topic, we have learned how to make a bookmark in Word with C# REST API. If you are looking to convert a Word file to an HTML file, refer to the article on Convert DOCX to HTML with NET REST API.