//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Linq;usingGrapeCity.Documents.Word;usingRange = GrapeCity.Documents.Word.Range; namespaceDsWordWeb.Demos{// This sample shows how to split a DOCX into several documents. // To see see the original document, run the SampleParagraphs sample.publicclassSplitDocs {publicGcWordDocumentCreateDocx() {// The document will be split before the paragraph beginning with:conststringp2start = "This is the second paragraph of the original document"; var doc = newGcWordDocument(); doc.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx")); Range rng0 = null, rng1 = null;foreach (var p in doc.Body.Paragraphs)if (p.GetRange().Text.StartsWith(p2start)) { rng0 = doc.Body.GetPersistentRange(doc.Body.Start, p.Previous.End); rng1 = doc.Body.GetPersistentRange(p.Start, doc.Body.End);break; } if (rng0 == null || rng1 == null)thrownewException("Unexpected: could not find the split point."); var docs = doc.SplitDocument(rng0, rng1);if (docs.Count() != 2)thrownewException("Unexpected: the split should have returned 2 documents."); // Return the 2nd of the two documents (the one starting with 'p2start':return docs.Last(); } }}