This article entails how to merge Word documents using C#. It represents a step-by-step process, the link to the required resources for configuring the IDE, and a working sample code for developing an application that can concatenate Word files using C#. The developed application can be used inside any .NET configured environment in MS Windows, Linux, or macOs.
Steps to Merge Word Documents in C#
- Configure the IDE to use Aspose.Words for .NET to combine Word document in C#
- Access the source Word file using an instance of the Document class
- Access the Target Word document using an instance of the Document class
- Append the Source Word document into the Target Word document using the AppendDocument method
- Save the Target Word document on the disk
The aforementioned simple steps explain the process to combine Word documents in C#. The process is initiated by accessing the source and target Word documents from the disk using two separate instances of the Document Class. Then by using AppendDocument method of the target’s document class object, the source document is appended inside the target document, which is then followed by saving the combined Word document file on the disk.
Code to Combine Word Documents using C#
The above example code in C# merge Word documents using a very simple API interface. The example can be easily extended to merge as many as required DOCX files together. The AppendDocument method takes ImportFormatMode enum as a parameter, which gives options to merge the incoming Word file either by using the source formatting, destination formatting, or keeping only different styles. One can merge the document suiting any enumerator choice as required and save the document on the disk using the Save method.
This guide has taught us how to append Word Documents using C#. If you want to learn the process of converting an HTML file to a Word document, refer to the article on how to convert HTML to Word Document using C#.