Comments.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Linq;
  9. using GrapeCity.Documents.Word;
  10.  
  11. namespace DsWordWeb.Demos
  12. {
  13. // This sample demonstrates how to add comments to parts of document.
  14. // When exporting a document with comments to PDF, by default comments
  15. // are also exported. This behavior can be changed using the
  16. // PdfConversionOptions parameter in SaveAsPdf method.
  17. public class Comments
  18. {
  19. public GcWordDocument CreateDocx()
  20. {
  21. var user1 = "Jaime Smith"; // user name for comments' author
  22. var user2 = "Jane Donahue"; // user name for comments' author
  23.  
  24. var doc = new GcWordDocument();
  25.  
  26. var pars = doc.Body.Paragraphs;
  27.  
  28. var p1 = pars.Add("Paragraph 1: This is a paragraph of text with a comment added to the whole paragraph. ");
  29. var c1 = p1.GetRange().Comments.Add("Comment added to paragraph 1.", user1, Util.TimeNow(), "J.S.");
  30. var c2 = c1.Reply("Reply to comment 1.", user2);
  31. var c3 = c2.Reply("Reply to comment 2, closing the thread.", user1);
  32. c3.Done = true;
  33.  
  34. var p2 = pars.Add("Paragraph 2: This is another paragraph of text, with a comment added to 3rd run. ");
  35. p2.GetRange().Runs.Add("This is run 2 of paragraph 2. ");
  36. var r = p2.GetRange().Runs.Add("This is run 3 of paragraph 2 with a comment. ");
  37. r.GetRange().Comments.Insert("Comment on run 3 of paragraph 2", user2, RangeLocation.Whole);
  38. p2.GetRange().Runs.Add("This is run 4 of paragraph 2. ");
  39. p2.GetRange().Runs.Add("This is run 5 of paragraph 2. ");
  40. p2.GetRange().Runs.Add("This is run 6 of paragraph 2. ");
  41.  
  42. // Done:
  43. return doc;
  44. }
  45. }
  46. }
  47.