The Syncfusion .NET Word Library (DocIO) offers powerful APIs to programmatically split large Word documents into multiple smaller ones with ease. Achieve document segmentation in just a few lines of code, all without relying on Microsoft Word or interop dependencies.
This sample code shows how to split a Word document by sections using the Syncfusion .NET Word Library with just few lines of code in C#.
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
// Open the Word document stream.
using (FileStream inputStream = new FileStream(@"Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
// Load an existing Word document.
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
// Iterate through each section in the document.
for (int i = 0; i < document.Sections.Count; i++)
{
// Create a new Word document for each section.
using (WordDocument newDocument = new WordDocument())
{
// Add the cloned section to the new document.
newDocument.Sections.Add(document.Sections[i].Clone());
// Save the section as a separate Word document.
using (FileStream outputStream = new FileStream(@"Section" + i + ".docx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
newDocument.Save(outputStream, FormatType.Docx);
}
}
}
}
}
Iterates through the document content section by section and saves each section as an individual Word document.
Extracts the content of a heading in the Word document by iterating the document contents and saves the extracted content as an individual Word document.
Extracts a part of a document based on placeholder text and saves the extracted content as an individual Word document.
Retrieves content within a bookmark and saves it as a separate Word document.
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
You can split a Word document by sections, bookmarks, headings, and placeholder text.
Yes, you can maintain the chapters’ titles with heading styles and split the Word document by headings using the .NET Word Library.
Yes, use the find functionality to find the keywords or content and then split the Word document into separate documents.
Yes, you can merge the split Word document’s pieces later using the merge functionality of the .NET Word Library.
Yes, you can programmatically split Word documents and convert them into PDF, image, or HTML formats.
You can access it through the Syncfusion.DocIO.Net.Core NuGet package. Detailed code samples and tutorial videos are available in the documentation.
Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion® is proud to hold the following industry awards.