Hi,
I’m using your Aspose.Words product on a .NET application and i’m facing an issue when i’m trying to add a comment in a content control. I’ve attached you the document (Word document_preview.zip (14.8 KB)) which causes the issue.
Here is my code :
Document _document;
public void UpdateDocumentContentControl()
{
_document = new Document(inputDocFilePath);
List<StructuredDocumentTag> sdtList = _document.GetChildNodes(NodeType.StructuredDocumentTag, isDeep: true).Cast<StructuredDocumentTag>().ToList();
foreach (var sdt in sdtList)
{
CreateFieldMarkComment(sdt);
}
}
public void CreateFieldMarkComment(StructuredDocumentTag sdt)
{
var text = "NO DATA";
var commentText = "ReadOnlyContext:None";
AddTextAndComment(sdt, text, commentText);
}
public void AddTextAndComment(StructuredDocumentTag sdt, string text, string commentText)
{
// https://docs.aspose.com/display/wordsnet/Working+with+Comments
var paragraph = new Paragraph(_document);
paragraph.AppendChild(new Run(_document, commentText));
var comment = new Aspose.Words.Comment(_document);
comment.AppendChild(paragraph);
sdt.RemoveAllChildren();
sdt.AppendChild(comment); // System.ArgumentException => Cannot insert a node of this type at this location.
sdt.AppendChild(new CommentRangeStart(_document, 654));
sdt.AppendChild(new Run(_document, text));
sdt.AppendChild(new CommentRangeEnd(_document, 654));
}
Thanks for your help,
Regards,