Combine Word Documents in C#

In our previous article, we covered how to join Word documents in Node.js. This blog post explains how to merge Word documents in C#. For this purpose, we will leverage GroupDocs.Merger Cloud SDK for .Net to combine Word documents programmatically. In fact, automating the document merging process will eventually boost productivity and provide a competitive edge. Therefore, go through this blog post carefully to learn how to merge Word documents in C#. In addition, we will go through the code snippet step by step to implement the functionality.

We will cover the following sections in this article:

Word Files Merger - API Installation

Well, the installation of this enterprise-level API is very simple as it is easy to install. All you need to do is download the NuGet package or run the following command in the NuGet Package Manager:

Install-Package GroupDocs.Merger-Cloud -Version 23.4.0

Please visit this link to learn the steps of getting API credentials(Client ID + Client Secret).

Combine Word Documents in C# Programmatically

So, once you have set up the GroupDocs.Merger Cloud SDK for .Net, we are all set to start writing code snippet to merge Word documents programmatically.

Note: We have uploaded two different Docx/Docs files on the API cloud dashboard. However, you may automate this task by calling the UploadFile method.

You may follow the following steps to achieve this functionality:

  • Initialize an instance of the Configuration class with the Client ID and Client Secret.
  • Instantiate an instance of the DocumentApi with the object of the Configuration class.
  • Create an object of the JoinItem class.
  • Initialize an instance of the FileInfo class and set the path of the first Word document.
  • Instantiate an object of the FileInfo class and set the path of the second Word document.
  • Create an object of the JoinOptions class and set the path for the generated file.
  • Create an instance of the JoinRequest class and initialize it with the object of the JoinOptions class.
  • Invoke the Join method to combine Word documents.

Copy & paste the following code snippet into your main server file and run the server to combine Word documents programmatically:

The out can be seen in the image below:

Merge Word Documents

Merge Word Files Online

Luckily, there is an online tool that lets users merge Word documents instantly and is powered by GroupDocs.Merger Cloud SDKs. It comes with a logical interface and is easy to use. Above all, it is free and anyone can use it without any prior subscription.

merge word files online

Conclusion

We are ending this blog post here and we promise to come back with another useful article. So, we have learned how to combine Word documents in C#. In addition, we also went through the steps and the code snippet to merge Word documents programmatically. This article will help you if you are looking to build a Word file merger module for your business application. Therefore, please go through the documentation to learn further features of GroupDocs.Merger Cloud SDKs. Also, do not forget to give a try to our live version of API. Further, we recommend you follow our Getting Started guide.

Finally, groupdocs.cloud is writing new articles. So, please stay in touch for the latest updates.

Ask a question

You can let us know about your questions or queries on our forum.

Frequently Asked Questions – FAQs

How to merge two Word documents in C#?

Call the Join method to combine Word documents programmatically. GroupDocs.Merger Cloud SDK for .Net offers a rich stack of features to automate this process.

How do I automatically merge Word documents?

You may visit this link to learn the steps and the code snippet to merge Word documents automatically.

See Also