There are situations where you have data distributed across multiple documents and the requirement arises to combine all the documents/information or specific sections of them into a single file. In order to converge the data, this article will provide guidance on how to programmatically merge multiple Word documents into one using C#. Additionally, we will see how to combine only the selective pages of two or more Word files within the .NET application.

Word Merger – .NET API

In this article, I will utilize GroupDocs.Merger for .NET. It enables you to combine multiple Word documents into a single file. With this .NET API, I can effortlessly join documents of different or identical formats into one combined file. Moreover, the API provides a range of functionalities, such as splitting and trimming documents, as well as the ability to swap, move, remove, rotate, or arrange pages.

In case you are interested in the API features, you can go through its documentation, and also my favorite area, which is the running examples at GitHub.

To acquire the necessary DLLs or MSI installer, you can access the downloads section. Alternatively, you can install the API directly into your .NET application through NuGet.

PM> Install-Package GroupDocs.Merger

How to Merge Multiple Word Documents with C#

Merging Word documents into a single file is made simple with just a few lines of code. Follow these steps to combine two or more Word documents into one file using C#:

  • Begin by loading the source Word document using the Merger class.
  • Join the document to merge using the Join method.
  • Keep merging any additional Word document(s) using the same Join method.
  • Finally, save the merged document as output using the Save method.

Here’s an example of C# source code that demonstrates how to merge two or more Word documents into one file:

By following these steps and utilizing the provided C# code, you can effortlessly combine multiple Word documents into a single file.

Merge Selective Pages of Word files into One in C#

There are instances where you may not want to merge the complete document. Instead, you may only wish to select the specific pages from one document and combine them with selected pages from another document, and so on. Fortunately, the API offers various methods to merge selective pages from multiple Word documents into a single file.

Here are the steps to combine selective pages from multiple Word documents using C#:

  • Begin by loading the source document using the Merger class.
  • Set the merging options using the JoinOptions class.
  • Merge the document by invoking the Join method.
  • Continuously combine documents by adjusting the Join Options for each document as needed.
  • Finally, save the merged document using the Save method.

Take a look at the following source code, which demonstrates how to merge selective pages from Word documents into a single Word file using C#:

By following these steps and utilizing the provided C# code, you can merge selective pages from multiple Word documents into a single Word file.

Get a Free API License

You can get a free temporary license in order to use the API without the evaluation limitations.

Conclusion

In conclusion, we have covered the process of merging two or more Word documents into a single file using C# within a .NET application. Furthermore, we explored the method of combining specific pages from multiple Word files.

To further enhance your understanding of GroupDocs.Merger for .NET, I encourage you to refer to the documentation. If you have any questions or concerns, please don’t hesitate to reach out to us through our forum. We are here to assist you.

See Also