In the dynamic realm of document creation and collaboration, the ability to add and manage comments in Microsoft Word is indispensable. Comments serve as a virtual discussion board, allowing collaborators to exchange thoughts, suggest improvements, and provide feedback without altering the original content. This feature not only facilitates effective communication but also enhances the collaborative editing process, making it more streamlined and efficient. Therefore, in this guide, we’ll delve into the essential aspects of adding and deleting comments, unveiling the potential and benefits of this vital feature in MS Word using .NET REST API.
- Manage Comments using .NET REST API
- Get Comments from DOCX Files
- Insert comments in Word document
- Update comments in Word file
- Delete comments from Word document
Manage Comments using .NET REST API
Manipulating and adding comments using Aspose.Words Cloud SDK for .NET brings a wealth of benefits and a wide array of capabilities beyond just comment management. Apart from this, the SDK also offers a wide array of capabilities including Word document generation, Word to JPG, Word to PDF, Word to ODT etc conversion, text and formatting manipulation, image processing and a wide range of features, enabling you to enhance your document processing capabilities for an array of scenarios.
Get Comments from DOCX Files
You can leverage to read all or specific comments from the document. The GetComments method provides the capabilities to read the user comments from DOCX file. Specified below is a cURL command which you may use to read the comments on the command prompt.
cURL command
Please note that in order to read comments, you need to provide the details regarding documents stored on cloud storage, as well as only authorized users, get the permissions to access the APIs. Therefore, you need to first retrieve the JWT authentication token and use it in the command as mentioned above.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=xxxxxxx-1c8e-4ea4-a948-3857547232fa&client_secret=xxxxxx" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accpet: application/json"
Once the JWT token has been generated, please execute the following command to get all the comments within word document.
curl -v "https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments" \
-X GET \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>"
Request URL
https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments
C#.NET
In order to read a particular comment from the document, please follow the steps specified below:
- Initialize an instance of WordsApi class.
- Create an object of GetCommentRequest class where we provide the input Volume 1.docx file name and comment index value as input arguments.
- Finally, initialize an object of CommentResponse while passing the value returned from GetComment(..) method.
Get all comments
The API also offers the feature to get all comments from the document (in case we do not want to traverse between individuals). For this requirement, you need to create an instance of GetCommentsRequest, CommentsResponse classes, and call the GetComments(..) method of the WordsApi object.
Insert comments in Word document
The API is also capable of adding/inserting new comment objects in a word document.
cURL command
curl -v "https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments" \
-X POST \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"RangeStart\":{\"Node\":{\"link\":{\"Href\":\"https://api.aspose.cloud/v4.0/words/Volume 1.docx/sections/0/body/tables/0/rows/1/cells/1/paragraphs/1/runs/0\",\"Rel\":\"self\",\"Type\":\"string\",\"Title\":\"Heading 2\"},\"NodeId\":\"0.1.0.1.1.1.1\"},\"Offset\":0},\"RangeEnd\":{\"Node\":{\"link\":{\"Href\":\"https://api.aspose.cloud/v4.0/words/Volume 1.docx/sections/0/body/tables/0/rows/1/cells/1/paragraphs/5/runs/0\",\"Rel\":\"self\",\"Type\":\"string\",\"Title\":\"Heading 2\"},\"NodeId\":\"0.1.0.1.1.1.1\"},\"Offset\":0},\"Author\":\"Nayyer Shahbaz\",\"Initial\":\"MOU\",\"DateTime\":\"2020-12-07T04:10:03.942Z\",\"Text\":\"Comments Inserted using Aspose.Words Cloud API\"}"
C#.NET
Update comments in Word file
As well as parsing and addition of comments, the API also supports the feature to update the existing comments inside the word document.
cURL command
curl -X PUT "https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments/1" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"RangeStart\":{\"Node\":{\"link\":{\"Href\":\"https://api.aspose.cloud/v4.0/words/Volume 1.docx/sections/0/body/tables/0/rows/1/cells/1/paragraphs/1/runs/0\",\"Rel\":\"self\",\"Type\":\"string\",\"Title\":\"Heading 1\"},\"NodeId\":\"0.1.0.1.1.1.1\"},\"Offset\":0},\"RangeEnd\":{\"Node\":{\"link\":{\"Href\":\"https://api.aspose.cloud/v4.0/words/Volume 1.docx/sections/0/body/tables/0/rows/1/cells/1/paragraphs/1/runs/0\",\"Rel\":\"string\",\"Type\":\"string\",\"Title\":\"Heading 1\"},\"NodeId\":\"0.1.0.1.1.1.1\"},\"Offset\":0},\"Author\":\"Nayyer Shahbaz\",\"Initial\":\"Aspose.Words\",\"DateTime\":\"2020-12-07T06:18:31.348Z\",\"Text\":\"Comments updated using Aspose.Words Cloud API\"}"
C#.NET
In order to programmatically update the comments in Word document, please follow the instructions specified below.
- Create an instance of WordsApi class.
- Create an object of NodeLink which defines the comment NodeID.
- A new object of DocumentPosition class is created that defines RangeStart and RangeEnd values.
- Create an object of CommentUpdate which defines, comment Initials, Author name, RangeStart & RangeEnd details by assigning DocumentPosition instance value and the text to be updated in the comment.
The resultant document Volume 1 - updated.docx is also attached.
Delete comments from Word document
You can also remove/delete the comments from the word file using REST cloud API.
cURL command
curl -X DELETE "https://api.aspose.cloud/v4.0/words/Volume%201.docx/comments/0" \
-H "accept: /" \
-H "Authorization: Bearer <JWT Token>"
C#.NET
- Create an object of WordsApi class.
- Create an instance of DeleteCommentRequest class which takes an input file and index of comment as an argument.
- Finally the DeleteComment(…) method having DeleteCommentRequest object as an argument.