Add or Remove Comments in PowerPoint PPT in C#

While reviewing the content in PowerPoint presentations, the comments are used to write the feedback. The comments can be added against a particular word, phrase, or anything on a PPT slide. In this article, you will learn how to add comments to PowerPoint PPT slides in C#. Moreover, we will cover how to read or remove slide comments and add their replies.

C# .NET API to Add Comments in PowerPoint

To manipulate comments in PowerPoint presentations, we will use Aspose.Slides for .NET. It is a powerful API to create and manipulate PowerPoint presentations. You can either download API’s DLL or install it using NuGet.

PM> Install-Package Aspose.Slides.NET

Add Comments to PowerPoint PPT in C#

In PowerPoint presentations, every comment is attached with a particular author. Whereas, each comment contains some additional information such as time of creation, slide where it is added, and its position. The following are the steps to add comments to a PPT slide in C#.

The following code sample shows how to add comments to PowerPoint PPT slides in C#.

// Load presentation file or create a new one
using (Presentation presentation = new Presentation())
{
// Add an empty slide or get reference of an existing slide using presentation.Slides collection
presentation.Slides.AddEmptySlide(presentation.LayoutSlides[0]);
// Add an author
ICommentAuthor author = presentation.CommentAuthors.AddAuthor("Usman", "UA");
// Set the position for comment
PointF point = new PointF();
point.X = 0.2f;
point.Y = 0.2f;
// Add slide comment on first slide
author.Comments.AddComment("Hello, this is slide comment", presentation.Slides[0], point, DateTime.Now);
// Save presentation
presentation.Save("Comments_out.pptx", SaveFormat.Pptx);
}

The following is the screenshot of the comment we have added using the above code sample.

Insert Comments to PPT Slides in C#

Add Comment Replies in PPT in C#

Aspose.Slides also allows you to add replies to the comments. A reply itself is a comment which appears as a child of an existing comment. So let’s see how to add replies to comments in PowerPoint PPT slides in C#.

The following code sample shows how to add replies to comments in a PPTX slides in C#.

// Load presentation file or create a new one
using (Presentation presentation = new Presentation())
{
// Add author and comment
ICommentAuthor author = presentation.CommentAuthors.AddAuthor("Usman", "MF");
IComment comment = author.Comments.AddComment("Hello, this is slide comment.", presentation.Slides[0], new System.Drawing.PointF(0.2f, 0.2f), DateTime.Now);
// Add reply comment
IComment reply = author.Comments.AddComment("This is the reply to the comment.", presentation.Slides[0], new System.Drawing.PointF(0.2f, 0.2f), DateTime.Now);
reply.ParentComment = comment;
// Add reply comment
IComment reply2 = author.Comments.AddComment("This is second reply.", presentation.Slides[0], new System.Drawing.PointF(0.2f, 0.2f), DateTime.Now);
reply2.ParentComment = comment;
// Save presentation
presentation.Save("Comments_out.pptx", SaveFormat.Pptx);
}

The following screenshot shows the output of the above code sample.

Add reply to the comments in PPT

Read Comments from PPT Slides in C#

Using Aspose.Slides, you can either read comments of a particular author or all the authors. The following are the steps to read comments in PPT slides in C#.

The following code sample shows how to read comments in PowerPoint PPT slides in C#.

// Load presentation file
using (Presentation presentation = new Presentation("Comments_out.pptx"))
{
// Loop through authors
foreach (var commentAuthor in presentation.CommentAuthors)
{
// Loop through comments of author
var author = (CommentAuthor)commentAuthor;
foreach (var comment in author.Comments)
{
Console.WriteLine("ISlide :" + comment.Slide.SlideNumber + " has comment: " + comment.Text + " with Author: " + comment.Author.Name + " posted on time :" + comment.CreatedTime + "\n");
}
}
}

Remove Comments from PowerPoint PPT in C#

In the previous section, you have seen how to read a comment by accessing it from the comments collection. Similarly, you can remove a comment after getting its reference. The following code sample shows how to remove comments in PowerPoint presentations in C#.

// Load presentation
using (Presentation presentation = new Presentation("Comments_out.pptx"))
{
// Get first slide
ISlide slide = presentation.Slides[0];
// Get comments
var comments = slide.GetSlideComments(null);
// Remove desired comment using index
comments[0].Remove();
// Save presentation
presentation.Save("Comments_out.pptx", SaveFormat.Pptx);
}

C# PowerPoint API - Get a Free License

You can work with PowerPoint PPT comments without evaluation limitations by getting a free temporary license.

Conclusion

In this article, you have learned how to add comments in PowerPoint PPT slides in C#. Moreover, we have covered how to add replies to the comments programmatically. At the end, we have demonstrated how to read or remove comments from PPT slides. You can visit the documentation to explore more about Aspose.Slides for .NET. Also, you can post your queries to our forum.

See Also