How to remove comments in presentation (C# .NET)

Is there any ability to remove comments from pptx document?
Results_With_Comments.zip (48.6 KB)

By comments you mean notes? I just cannot get the source file.

Yeah. I sended you some examples with them, if I called them with wrong word correct me

image.png (1.1 KB)

@chub,

I have observed your requirements and suggest you to please try using following sample code on your end.

	public static void RemoveComments()
	{
		Presentation pres = new Presentation("Test.pptx");
		foreach (var commentAuthor in pres.CommentAuthors)
		{
			commentAuthor.Remove();
		}
	}

Version1.12.zip (25.3 KB)
That’s the result of what you send me, yes, author was deleted but comment left (Exception: Comment by nonexistent author. AuthorId = 0. in future files of course appeared, so it’s not the way i’m looking for.) I need some how delete this small notes from document;

@chub,

Can you please try using following modified code.

	public static void RemoveComments()
	{
		Presentation pres = new Presentation("Test.pptx");
		foreach (var commentAuthor in pres.CommentAuthors)
		{
			foreach (var coms in commentAuthor.Comments)
			{
				commentAuthor.Comments.Remove(coms);
			}
			
			commentAuthor.Remove();
		}
	}

Thanks a lot. I modified this sample because I had Collection was modified in foreach.
May be It will be useful for someone.

   public void RemoveComments()
    {
        Dictionary<ICommentAuthor, List<IComment>> commentsDictionary = new Dictionary<ICommentAuthor, List<IComment>>();
        foreach (var commentAuthor in presentation.CommentAuthors)
        {
            List<IComment> comments = new List<IComment>();
            foreach (var com in commentAuthor.Comments)
            {
                comments.Add(com);
            }
            commentsDictionary.Add(commentAuthor, comments);
        }

        foreach (var pair in commentsDictionary)
        {
            foreach (var comment in pair.Value)
            {
                pair.Key.Comments.Remove(comment);
            }
            pair.Key.Remove();
        }
    }

@chub,

It’s good to know that suggested option has worked on your end.

1 Like