Class CommentsCollection
Represents the collection of WComment in the Word document.
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class CommentsCollection : CollectionImpl
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load an existing Word document into DocIO instance
WordDocument document = new WordDocument("Comment.docx");
//Iterate the comments in the Word document
foreach (WComment comment in document.Comments)
{
//Modify the last paragraph text of an existing comment if it is added by "Peter"
if (comment.Format.User == "Peter")
comment.TextBody.LastParagraph.Text = "Modified Comment Content";
}
document.Save("ModifiedComment.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load an existing Word document into DocIO instance
Dim document As New WordDocument("Comment.docx")
'Iterate the comments in the Word document
For Each comment As WComment In document.Comments
'Modify the last paragraph text of an existing comment if it is added by "Peter"
If comment.Format.User = "Peter" Then
comment.TextBody.LastParagraph.Text = "Modified Comment Content"
End If
Next
document.Save("ModifiedComment.docx", FormatType.Docx)
document.Close()
End Sub
Constructors
CommentsCollection(WordDocument)
Initializes a new instance of the CommentsCollection class.
Declaration
public CommentsCollection(WordDocument doc)
Parameters
Type | Name | Description |
---|---|---|
WordDocument | doc | The WordDocument object. |
Properties
Item[Int32]
Gets the comment at specified index. Read-only.
Declaration
public WComment this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index of the comment in the collection. |
Property Value
Type | Description |
---|---|
WComment | The WComment at the specified index. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The index is not valid in the CommentsCollection |
Methods
Clear()
Removes all the comments from the document.
Declaration
public void Clear()
Examples
The following code example demonstrates how to remove all the comments from the document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load an existing Word document into DocIO instance
WordDocument document = new WordDocument("Comment.docx");
//Remove all the comments in a Word document
document.Comments.Clear();
//Save and close the Word document
document.Save("Result.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load an existing Word document into DocIO instance
Dim document As New WordDocument("Comment.docx")
'Remove all the comments in a Word document
document.Comments.Clear()
'Save and close the Word document
document.Save("Result.docx", FormatType.Docx)
document.Close()
End Sub
Counts()
Returns the total number of comments in the document. Read-only.
Declaration
public int Counts()
Returns
Type | Description |
---|---|
System.Int32 | The integer that specifies the total number of WComment in this CommentsCollection. |
Remove(WComment)
Removes the specified Comment.
Declaration
public void Remove(WComment comment)
Parameters
Type | Name | Description |
---|---|---|
WComment | comment | The WComment to be removed. |
Examples
The following code example demonstrates how to remove particular comment from the document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load an existing Word document into DocIO instance
WordDocument document = new WordDocument("Comment.docx");
//Get the second comment from a document.
WComment comment = document.Comments[1];
//Remove comment from a document.
document.Comments.Remove(comment);
//Save and close the Word document
document.Save("Result.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load an existing Word document into DocIO instance
Dim document As New WordDocument("Comment.docx")
'Get the second comment from a document.
Dim comment As WComment = document.Comments(1)
'Remove comment from a document.
document.Comments.Remove(comment)
'Save and close the Word document
document.Save("Result.docx", FormatType.Docx)
document.Close()
End Sub
RemoveAt(Int32)
Removes the WComment at specified index.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index of the comment to be removed. |
Examples
The following code example demonstrates how to remove the comment at specified index in the document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load an existing Word document into DocIO instance
WordDocument document = new WordDocument("Comment.docx");
//Remove the second comment from a document
document.Comments.RemoveAt(1);
//Save and close the Word document
document.Save("Result.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load an existing Word document into DocIO instance
Dim document As New WordDocument("Comment.docx")
'Remove the second comment from a document
document.Comments.RemoveAt(1)
'Save and close the Word document
document.Save("Result.docx", FormatType.Docx)
document.Close()
End Sub