How to Retrieve comments from a word processing document

How to Retrieve comments from a word processing document

2016-01-13 07:58:02 Written by  Koohji
Rate this item
(0 votes)

class Program
    {
        static void Main(string[] args)
        {
            string fileName = "OpenXML.docx";
            GetCommentsFromDocument(fileName);
        }
        public static void GetCommentsFromDocument(string fileName)
        {
            using (WordprocessingDocument wordDoc =
                WordprocessingDocument.Open(fileName, false))
            {
                WordprocessingCommentsPart commentsPart =
                    wordDoc.MainDocumentPart.WordprocessingCommentsPart;

                if (commentsPart != null && commentsPart.Comments != null)
                {
                    foreach (Comment comment in commentsPart.Comments.Elements())
                    {
                        Console.WriteLine(comment.InnerText);
                        
                    }
                }
            }
            Console.ReadLine();
        }
    }

Additional Info

  • tutorial_title: Retrieve comments from a word processing document
Last modified on Wednesday, 13 January 2016 07:58