How to get comments from a Word DOCX document hierarchically in C# .NET Framework

This lightning-quick tutorial will demonstrate how to extract comments from a Microsoft Word document and display them in a hierarchy, with replies treated as children of higher tier comments.

Our first order of business is to set up our API client via NuGet. Easy, just run this command in Package Manager:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

With that done, we can feed our DOCX file into the EditDocumentDocxGetCommentsHierarchical function, and let the API do the rest for us:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class EditDocumentDocxGetCommentsHierarchicalExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new EditDocumentApi();var reqConfig = new GetDocxGetCommentsHierarchicalRequest(); // GetDocxGetCommentsHierarchicalRequest | Document input requesttry{// Get comments from a Word DOCX document hierarchicallyGetDocxCommentsHierarchicalResponse result = apiInstance.EditDocumentDocxGetCommentsHierarchical(reqConfig);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentDocxGetCommentsHierarchical: " + e.Message );}}}}

Not bad, huh? Quite a bit of other info will be included in the response, so here is the general layout in which it will be given.

{
"Successful": true,
"Comments": [
{
"Path": "string",
"Author": "string",
"AuthorInitials": "string",
"CommentText": "string",
"CommentDate": "2020-02-09T05:03:27.152Z",
"ReplyChildComments": [
{
"Path": "string",
"Author": "string",
"AuthorInitials": "string",
"CommentText": "string",
"CommentDate": "2020-02-09T05:03:27.152Z",
"IsTopLevel": true,
"IsReply": true,
"ParentCommentPath": "string",
"Done": true
}
],
"Done": true
}
],
"TopLevelCommentCount": 0
}
Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store