Comments.cs
//
// This code is part of GrapeCity Documents for Word samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
//
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using GrapeCity.Documents.Word;

namespace GcWordWeb.Samples
{
    // This sample demonstrates how to add comments to parts of document.
    // When exporting a document with comments to PDF, by default comments
    // are also exported. This behavior can be changed using the 
    // PdfConversionOptions parameter in SaveAsPdf method. 
    public class Comments
    {
        public GcWordDocument CreateDocx()
        {
            var user1 = "Jaime Smith"; // user name for comments' author
            var user2 = "Jane Donahue"; // user name for comments' author

            var doc = new GcWordDocument();

            var pars = doc.Body.Sections.First.GetRange().Paragraphs;

            var p1 = pars.Add("Paragraph 1: This is a paragraph of text with a comment added to the whole paragraph. ");
            var c1 = p1.GetRange().Comments.Add("Comment added to paragraph 1.", user1, DateTime.Now, "J.S.");
            var c2 = c1.Reply("Reply to comment 1.", user2);
            var c3 = c2.Reply("Reply to comment 2, closing the thread.", user1);
            c3.Done = true;

            var p2 = pars.Add("Paragraph 2: This is another paragraph of text, with a comment added to 3rd run. ");
            p2.GetRange().Runs.Add("This is run 2 of paragraph 2. ");
            var r = p2.GetRange().Runs.Add("This is run 3 of paragraph 2 with a comment. ");
            r.GetRange().Comments.Insert("Comment on run 3 of paragraph 2", user2, RangeLocation.Whole);
            p2.GetRange().Runs.Add("This is run 4 of paragraph 2. ");
            p2.GetRange().Runs.Add("This is run 5 of paragraph 2. ");
            p2.GetRange().Runs.Add("This is run 6 of paragraph 2. ");

            // Done:
            return doc;
        }
    }
}