.NET Word Examples
- Create Word Document
- Perform Mail Merge
- Manage Bookmarks
- Find and Replace Text
- Format Tables
- Split Word Documents
- Merge Multiple Word Documents
- Fill and Manage Form Fields
- Generate and Update Table of Contents
- Compare Word Documents
- Encrypt and Decrypt Documents with Password
- Convert Word Documents to PDF
- Convert Word Documents to Images
- Word-HTML Conversions
- Word-Markdown Conversions
- Word-Text Conversions
Merge Word Documents Using the Syncfusion .NET Word Library
The Syncfusion® .NET Word Library provides powerful and comprehensive APIs to merge multiple Word documents into a single document. With just a few lines of code, you can streamline the process without relying on Microsoft Word or interop dependencies.
Watch this video to learn how to merge Word documents using the Syncfusion .NET Word Library.
Merge Word documents using C#
Learn how to merge multiple Word documents into a single document programmatically using C# with the Syncfusion .NET Word Library. This guide demonstrates combining documents by importing content from source to destination documents.
Step 1: Create a new project
Start by creating a new C# Console Application project.
Step 2: Install the NuGet package
Add the Syncfusion.DocIO.Net.Core package to your project from NuGet.org.
Step 3: Add required namespaces to merge Word documents
Add the following namespaces to your Program.cs file:
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;Step 4: Open source and destination documents
Open both the source and destination Word documents from file streams.
FileStream sourceStreamPath = new FileStream(Path.GetFullPath(@"Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Open an source document from file system through constructor of WordDocument class
WordDocument sourceDocument = new WordDocument(sourceStreamPath, FormatType.Automatic);
FileStream destinationStreamPath = new FileStream(Path.GetFullPath(@"Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Open the destination document
WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic);Step 5: Import content from source to destination
Import the contents of the source document into the destination document.
//Import the contents of source document at the end of destination document
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);Step 6: Save the Word document
Save the merged destination document to a file stream.
//Create file stream
FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite);
//Save the Word document to file stream
destinationDocument.Save(outputFileStream, FormatType.Docx);
// Close streams and documents explicitly
outputFileStream.Close();
destinationDocument.Close();
destinationStreamPath.Close();
sourceDocument.Close();
sourceStreamPath.Close();GitHub project
NuGet installation
Get started quickly by downloading the installer and checking license information on the Downloads page.
Table of contents
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Learning
Technical Support
