CanAddPara.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.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using GrapeCity.Documents.Word;
  11.  
  12. namespace DsWordWeb.Demos
  13. {
  14. // This example shows how to use ContentObject.CanAdd() method to test
  15. // whether a paragraph can be added to a content control.
  16. public class CanAddPara
  17. {
  18. public GcWordDocument CreateDocx()
  19. {
  20. var doc = new GcWordDocument();
  21. var p = doc.Body.Paragraphs.Add();
  22. var cc = p.AddContentControl(ContentControlType.RichText).Content;
  23. if (cc.CanAdd(typeof(Paragraph))) // returns false since the content control was created on inline level
  24. cc.AddParagraph("Paragraph added to Rich Text Content Control.");
  25. else
  26. cc.AddRun("Run added to Rich Text Content Control.");
  27. // Done:
  28. return doc;
  29. }
  30. }
  31. }
  32.