//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingGrapeCity.Documents.Word; namespaceDsWordWeb.Demos{// This sample shows how to copy or move ranges within a document,// or between documents, using the RangeBase.CopyTo()/MoveTo() methods.//// The original SampleParagraphs.docx used in this sample can be // seen by running the SampleParagraphs sample.publicclassRangeCopyMove {publicGcWordDocumentCreateDocx() {conststringp1start = "This is the first paragraph of the original document";conststringp2start = "This is the second paragraph of the original document";conststringp3start = "This is the third paragraph of the original document";conststringp4start = "This is the fourth paragraph of the original document"; // Load the sample DOCX file (see SampleParagraphs) into a GcWordDocument instance:var srcDoc = newGcWordDocument(); srcDoc.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx")); // Get the range of paragraphs to copy:var srcRng = srcDoc.Body.GetPersistentRange(srcDoc.Body.Paragraphs[2], srcDoc.Body.Paragraphs.Last); // We use another document here to demonstrate that CopyTo()/MoveTo() methods// can be used to copy/move content between documents:var doc = newGcWordDocument(); srcRng.CopyTo(doc.Body, InsertLocation.Start); // Find individual paragraphs inside the new document to manipulate:Paragraph p1 = null, p2 = null, p3 = null, p4 = null;foreach (var p in doc.Body.Paragraphs) {var t = p.GetRange().Text;if (t.StartsWith(p1start)) p1 = p;elseif (t.StartsWith(p2start)) p2 = p;elseif (t.StartsWith(p3start)) p3 = p;elseif (t.StartsWith(p4start)) p4 = p; }if (p1 == null || p2 == null || p3 == null || p4 == null)thrownewException("Unexpected: could not find paragraphs."); // Move first paragraph to the end of the document with default formatting option// (preserve formatting): p1.GetRange().MoveTo(doc.Body, InsertLocation.End); // Move second paragraph to the end of the document, clearing formatting: p2.GetRange().MoveTo(doc.Body, InsertLocation.End, FormattingCopyStrategy.Clear); // Copy third paragraph to the end of the document, clearing formatting: p3.GetRange().CopyTo(doc.Body, InsertLocation.End, FormattingCopyStrategy.Clear); // Add a note at the end of the document: doc.Body.Sections.Last.GetRange().Paragraphs.Add($"Created by DsWord on {Util.TimeNow():R}."); // Done:return doc; } }}