This article entails the process to replace a word in Word with NET REST API. You will use Aspose.Words for .NET Cloud SDK to change a word in Word with C# REST API in the cloud using a few API calls. It discusses various options to customize the text replacement operation.
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 to replace text
Steps to Change Word in Word with C# Low Code API
- Instantiate the WordsApi object using the client ID and secret
- Read the input Word file into a memory stream
- Create the ReplaceTextParameters object and set the old text, new text, and other flags
- Set the output file name and call the ReplaceTextOnline() method with the custom request
- Get the output file contents from the API response and save on the local disk
The aforementioned steps define the process to replace words in Word DOC with C# REST API. Initiate the process by loading the source Word file into the memory stream followed by creating the replace text request using the ReplaceTextParameters and setting the old text value, new text value, flag to match case, match whole word and presence of regex in the old text value. Finally, call the ReplaceTextOnline() method to replace text online and fetch the output Word file from the API response.
Code to Replace Word in Word DOC with NET REST API
This sample code exhibits how to replace a word in Word document with C# Low Code API. We set the DestFileName to the output file name that we use to fetch the resultant Word file using the TryGetValue() method in the API call result. Create a file stream using the File.Create method and save the output to the local disk using this stream.
In this topic, we have learned to find and replace text online in a Word file. To change Word document properties, refer to the following article: Change Properties of Word Document with NET REST API.