Comment
Comment class
Represents a container for text of a comment.
To learn more, visit the Working with Comments documentation article.
public sealed class Comment : InlineStory
Constructors
Name | Description |
---|---|
Comment(DocumentBase) | Initializes a new instance of the Comment class. |
Comment(DocumentBase, string, string, DateTime) | Initializes a new instance of the Comment class. |
Properties
Name | Description |
---|---|
Ancestor { get; } | Returns the parent Comment object. Returns null for top-level comments. |
Author { get; set; } | Returns or sets the author name for a comment. |
Count { get; } | Gets the number of immediate children of this node. |
CustomNodeId { get; set; } | Specifies custom node identifier. |
DateTime { get; set; } | Gets the date and time that the comment was made. |
DateTimeUtc { get; } | Gets the UTC date and time that the comment was made. |
virtual Document { get; } | Gets the document to which this node belongs. |
Done { get; set; } | Gets or sets flag indicating that the comment has been marked done. |
FirstChild { get; } | Gets the first child of the node. |
FirstParagraph { get; } | Gets the first paragraph in the story. |
Font { get; } | Provides access to the font formatting of the anchor character of this object. |
HasChildNodes { get; } | Returns true if this node has any child nodes. |
Id { get; set; } | Gets or sets the comment identifier. |
Initial { get; set; } | Returns or sets the initials of the user associated with a specific comment. |
override IsComposite { get; } | Returns true as this node can have child nodes. |
IsDeleteRevision { get; } | Returns true if this object was deleted in Microsoft Word while change tracking was enabled. |
IsInsertRevision { get; } | Returns true if this object was inserted in Microsoft Word while change tracking was enabled. |
IsMoveFromRevision { get; } | Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled. |
IsMoveToRevision { get; } | Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled. |
LastChild { get; } | Gets the last child of the node. |
LastParagraph { get; } | Gets the last paragraph in the story. |
NextSibling { get; } | Gets the node immediately following this node. |
override NodeType { get; } | Returns Comment. |
Paragraphs { get; } | Gets a collection of paragraphs that are immediate children of the story. |
ParentId { get; set; } | Gets or sets the parent comment ID. A value of -1 means the comment has no parent. |
ParentNode { get; } | Gets the immediate parent of this node. |
ParentParagraph { get; } | Retrieves the parent Paragraph of this node. |
PreviousSibling { get; } | Gets the node immediately preceding this node. |
Range { get; } | Returns a Range object that represents the portion of a document that is contained in this node. |
Replies { get; } | Returns a collection of Comment objects that are immediate children of the specified comment. |
override StoryType { get; } | Returns Comments. |
Tables { get; } | Gets a collection of tables that are immediate children of the story. |
Methods
Name | Description |
---|---|
override Accept(DocumentVisitor) | Accepts a visitor. |
override AcceptEnd(DocumentVisitor) | Accepts a visitor for visiting the end of the comment. |
override AcceptStart(DocumentVisitor) | Accepts a visitor for visiting the start of the comment. |
AddReply(string, string, DateTime, string) | Adds a reply to this comment. |
AppendChild<T>(T) | Adds the specified node to the end of the list of child nodes for this node. |
Clone(bool) | Creates a duplicate of the node. |
CreateNavigator() | Creates navigator which can be used to traverse and read nodes. |
EnsureMinimum() | If the last child is not a paragraph, creates and appends one empty paragraph. |
GetAncestor(NodeType) | Gets the first ancestor of the specified NodeType . |
GetAncestor(Type) | Gets the first ancestor of the specified object type. |
GetChild(NodeType, int, bool) | Returns an Nth child node that matches the specified type. |
GetChildNodes(NodeType, bool) | Returns a live collection of child nodes that match the specified type. |
GetEnumerator() | Provides support for the for each style iteration over the child nodes of this node. |
override GetText() | Gets the text of this node and of all its children. |
IndexOf(Node) | Returns the index of the specified child node in the child node array. |
InsertAfter<T>(T, Node) | Inserts the specified node immediately after the specified reference node. |
InsertBefore<T>(T, Node) | Inserts the specified node immediately before the specified reference node. |
NextPreOrder(Node) | Gets next node according to the pre-order tree traversal algorithm. |
PrependChild<T>(T) | Adds the specified node to the beginning of the list of child nodes for this node. |
PreviousPreOrder(Node) | Gets the previous node according to the pre-order tree traversal algorithm. |
Remove() | Removes itself from the parent. |
RemoveAllChildren() | Removes all the child nodes of the current node. |
RemoveAllReplies() | Removes all replies to this comment. |
RemoveChild<T>(T) | Removes the specified child node. |
RemoveReply(Comment) | Removes the specified reply to this comment. |
RemoveSmartTags() | Removes all SmartTag descendant nodes of the current node. |
SelectNodes(string) | Selects a list of nodes matching the XPath expression. |
SelectSingleNode(string) | Selects the first Node that matches the XPath expression. |
SetText(string) | This is a convenience method that allows to easily set text of the comment. |
ToString(SaveFormat) | Exports the content of the node into a string in the specified format. |
ToString(SaveOptions) | Exports the content of the node into a string using the specified save options. |
Remarks
A comment is an annotation which is anchored to a region of text or to a position in text. A comment can contain an arbitrary amount of block-level content.
If a Comment
object occurs on its own, the comment is anchored to the position of the Comment
object.
To anchor a comment to a region of text three objects are required: Comment
, CommentRangeStart
and CommentRangeEnd
. All three objects need to share the same Id
value.
Comment
is an inline-level node and can only be a child of Paragraph
.
Comment
can contain Paragraph
and Table
child nodes.
Examples
Shows how to add a comment to a paragraph.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Hello world!");
Comment comment = new Comment(doc, "John Doe", "JD", DateTime.Today);
builder.CurrentParagraph.AppendChild(comment);
builder.MoveTo(comment.AppendChild(new Paragraph(doc)));
builder.Write("Comment text.");
Assert.AreEqual(DateTime.Today, comment.DateTime);
// In Microsoft Word, we can right-click this comment in the document body to edit it, or reply to it.
doc.Save(ArtifactsDir + "InlineStory.AddComment.docx");
Shows how to add a comment to a document, and then reply to it.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Comment comment = new Comment(doc, "John Doe", "J.D.", DateTime.Now);
comment.SetText("My comment.");
// Place the comment at a node in the document's body.
// This comment will show up at the location of its paragraph,
// outside the right-side margin of the page, and with a dotted line connecting it to its paragraph.
builder.CurrentParagraph.AppendChild(comment);
// Add a reply, which will show up under its parent comment.
comment.AddReply("Joe Bloggs", "J.B.", DateTime.Now, "New reply");
// Comments and replies are both Comment nodes.
Assert.AreEqual(2, doc.GetChildNodes(NodeType.Comment, true).Count);
// Comments that do not reply to other comments are "top-level". They have no ancestor comments.
Assert.Null(comment.Ancestor);
// Replies have an ancestor top-level comment.
Assert.AreEqual(comment, comment.Replies[0].Ancestor);
doc.Save(ArtifactsDir + "Comment.AddCommentWithReply.docx");
See Also
- class InlineStory
- namespace Aspose.Words
- assembly Aspose.Words