Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active July 1, 2025 11:47
Show Gist options
  • Save GroupDocsGists/74a22b37b74960f650c64c1a32a0b495 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/74a22b37b74960f650c64c1a32a0b495 to your computer and use it in GitHub Desktop.
How to merge Word documents in C#

Merge Word Documents in C#

If you need to merge Word documents in C#, this example shows how, complete with commentary and best practices. Merging documents is crucial for creating consolidated reports or combining multiple sections seamlessly into a single file. This guide utilizes a straightforward .NET example to illustrate various techniques for combining DOCX files efficiently.

📦 Prerequisites

Before you begin, ensure you have the necessary tools:

  • Install GroupDocs.Merger from NuGet.
  • Activate your GroupDocs license key for full functionality.

You can download a free trial of GroupDocs.Merger and use a temporary license for unlimited access to our library. This works for various file types including DOCX and DOC.

🧩 Key Capabilities

Here's what you'll learn about merging Word documents:

  • Merge multiple DOCX files into a single document effortlessly.
  • Control whether to include section breaks for smoother transitions.
  • Merge documents continuously without starting a new page.
  • Utilize predefined compliance modes for merging DOCX files.
  • Easily manage and save to specific output paths.

💻 Code Examples

See the following example 1: MergeDocx.cs

See the following example 2: MergeWordDocumentsWithoutSectionBreaks.cs

See the following example 3: MergeWordDocumentsWithoutStartingFromNewPage.cs

See the following example 4: MergeWordDocumentsWithPredefinedComplianceMode.cs

✅ How to Use in .NET

  1. Install the GroupDocs.Merger package using NuGet.
  2. Load your DOCX documents that you wish to merge.
  3. Configure the desired join options, such as handling section breaks.
  4. Merge the documents and save them to your desired output file path.
  5. Verify the merged document to ensure accuracy and formatting.
  6. This functionality supports various file types, including DOCX and DOC.

📎 Related Resources

📜 Conclusion

That’s it! Now you know how to merge Word documents in C# effectively. By following these steps, you can streamline your document management processes and maintain document integrity. Explore further capabilities by checking out our documentation or grabbing a trial license to fully discover the potential of our tools.

using System;
using System.IO;
namespace GroupDocs.Merger.Examples.CSharp.BasicUsage
{
/// <summary>
/// This example demonstrates how to merge multiple DOCX files into single file.
/// For more details about merging Microsoft Word Open XML Document (.docx) files please check this documentation article
/// https://docs.groupdocs.com/merger/net/merge/word/
/// </summary>
internal static class MergeDocx
{
public static void Run()
{
Console.WriteLine("=======================================================================");
Console.WriteLine();
Console.WriteLine("Example Basic Usage: MergeDocx");
Console.WriteLine();
string outputFolder = Constants.GetOutputDirectoryPath();
string outputFile = Path.Combine(outputFolder, "merged.docx");
// Load the source DOCX file
using (var merger = new GroupDocs.Merger.Merger(Constants.SAMPLE_DOCX))
{
// Add another DOCX file to merge
merger.Join(Constants.SAMPLE_DOCX_2);
// Merge DOCX files and save result
merger.Save(outputFile);
}
Console.WriteLine("\nDOCX files merge completed successfully. \nCheck output in {0}", outputFolder);
}
}
}
using GroupDocs.Merger.Domain.Options;
using System;
using System.IO;
namespace GroupDocs.Merger.Examples.CSharp.BasicUsage
{
/// <summary>
/// This example demonstrates how merge Word documents without section breaks into single file.
/// For more details about merging Microsoft Word Document (.doc) files please check this documentation article
/// https://docs.groupdocs.com/merger/net/merge/word/
/// </summary>
internal static class MergeWordDocumentsWithoutSectionBreaks
{
public static void Run()
{
Console.WriteLine("=======================================================================");
Console.WriteLine();
Console.WriteLine("Example Basic Usage: MergeWordDocumentsWithoutSectionBreaks");
Console.WriteLine();
string outputFolder = Constants.GetOutputDirectoryPath();
string outputFile = Path.Combine(outputFolder, "merged.doc");
// Load the source DOC file
using (var merger = new GroupDocs.Merger.Merger(Constants.SAMPLE_DOC))
{
// Define Word join options
WordJoinOptions joinOptions = new WordJoinOptions();
joinOptions.Mode = WordJoinMode.DisableSectionBreaks;
// Add another DOC file to merge
merger.Join(Constants.SAMPLE_DOC_2, joinOptions);
// Merge DOC files and save result
merger.Save(outputFile);
}
Console.WriteLine("\nDOC files merge completed successfully. \nCheck output in {0}", outputFolder);
}
}
}
using GroupDocs.Merger.Domain.Options;
using System;
using System.IO;
namespace GroupDocs.Merger.Examples.CSharp.BasicUsage
{
/// <summary>
/// This example demonstrates how merge Word documents without starting from a new page into single file.
/// For more details about merging Microsoft Word Document (.doc) files please check this documentation article
/// https://docs.groupdocs.com/merger/net/merge/word/
/// </summary>
internal static class MergeWordDocumentsWithoutStartingFromNewPage
{
public static void Run()
{
Console.WriteLine("=======================================================================");
Console.WriteLine();
Console.WriteLine("Example Basic Usage: MergeWordDocumentsWithoutStartingFromNewPage");
Console.WriteLine();
string outputFolder = Constants.GetOutputDirectoryPath();
string outputFile = Path.Combine(outputFolder, "merged.doc");
// Load the source DOC file
using (var merger = new GroupDocs.Merger.Merger(Constants.SAMPLE_DOC))
{
// Define Word join options
WordJoinOptions joinOptions = new WordJoinOptions();
joinOptions.Mode = WordJoinMode.Continuous;
// Add another DOC file to merge
merger.Join(Constants.SAMPLE_DOC_2, joinOptions);
// Merge DOC files and save result
merger.Save(outputFile);
}
Console.WriteLine("\nDOC files merge completed successfully. \nCheck output in {0}", outputFolder);
}
}
}
using GroupDocs.Merger.Domain.Options;
using System;
using System.IO;
namespace GroupDocs.Merger.Examples.CSharp.BasicUsage
{
/// <summary>
/// This example demonstrates how merge Word documents with pre-defined Compliance mode into single file.
/// For more details about merging Microsoft Word Document (.docx) files please check this documentation article
/// https://docs.groupdocs.com/merger/net/merge/word/
/// </summary>
internal static class MergeWordDocumentsWithPredefinedComplianceMode
{
public static void Run()
{
Console.WriteLine("=======================================================================");
Console.WriteLine();
Console.WriteLine("Example Basic Usage: MergeWordDocumentsWithPredefinedComplianceMode");
Console.WriteLine();
string outputFolder = Constants.GetOutputDirectoryPath();
string outputFile = Path.Combine(outputFolder, "merged.docx");
// Load the source DOCX file
using (var merger = new GroupDocs.Merger.Merger(Constants.SAMPLE_DOCX))
{
// Define Word join options
WordJoinOptions joinOptions = new WordJoinOptions();
joinOptions.Compliance = WordJoinCompliance.Iso29500_2008_Strict;
// Add another DOCX file to merge
merger.Join(Constants.SAMPLE_DOCX_2, joinOptions);
// Merge DOCX files and save result
merger.Save(outputFile);
}
Console.WriteLine("\nDOCX files merge completed successfully. \nCheck output in {0}", outputFolder);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment