Before running an example make sure that GroupDocs.Merger has been installed successfully.
We offer multiple ways to run GroupDocs.Merger examples — you can build your own project from scratch, or clone our back-end examples repository and run them out of the box.
Build a project from scratch
You can build a project from scratch using the .NET CLI or Visual Studio. Both paths are described below.
Create a directory for your console app by executing the mkdir my-console-app command in your terminal.
Navigate to the my-console-app directory by executing the cd my-console-app command.
Create an empty console app by executing the dotnet new console command.
Add the GroupDocs.Merger for .NET package by executing the dotnet add package GroupDocs.Merger command.
Edit Program.cs and add the following lines to the Main method:
usingGroupDocs.Merger;// The path to the documents directory.stringfirstDocPath=@"C:\sample.docx";// NOTE: Put the actual path to your document herestringsecondDocPath=@"C:\sample2.docx";// NOTE: Put the actual path to your document herestringoutputPath=@"C:\output\result.docx";// Join two documents and save as result.docx.using(Mergermerger=newMerger(firstDocPath)){merger.Join(secondDocPath);merger.Save(outputPath);}
Replace the firstDocPath and secondDocPath values with the actual paths to the documents you want to merge.
Run the project by executing the dotnet run command.
The merged document will be saved to the C:\output\ directory.
Build a project using Visual Studio
This method applies to both .NET 6+ and .NET Framework 4.6.2+ projects.
Open Visual Studio and go to File -> New -> Project.
Select the appropriate project type — Console App, ASP.NET Web Application, etc.
Install GroupDocs.Merger for .NET from NuGet. For detailed installation instructions, see the Installation guide.
Add the following code to the Main method:
usingGroupDocs.Merger;// The path to the documents directory.stringfirstDocPath=@"C:\sample.docx";// NOTE: Put the actual path to your document herestringsecondDocPath=@"C:\sample2.docx";// NOTE: Put the actual path to your document herestringoutputPath=@"C:\output\result.docx";// Join two documents and save as result.docx.using(Mergermerger=newMerger(firstDocPath)){merger.Join(secondDocPath);merger.Save(outputPath);}
Replace the firstDocPath and secondDocPath values with the actual paths to the documents you want to merge.
Build and Run your project.
The merged document will be saved to the C:\output\ directory.
Run back-end examples
The complete examples package of GroupDocs.Merger is hosted on GitHub. You can either download the ZIP file from here or clone the repository using your favorite Git client.
If you download the ZIP file, extract the folder on your local disk. The repository contains:
Examples/GroupDocs.Merger.Examples.CSharp.sln — the main C# solution that bundles example projects for .NET (GroupDocs.Merger.Examples.CSharp.Net) and .NET Framework (GroupDocs.Merger.Examples.CSharp.Framework).
Examples/GroupDocs.Merger.Examples.CSharp/Resources/ — sample documents and images used by the examples.
Examples/GroupDocs.Merger.Examples.CSharp/RunExamples.cs — the entry point that dispatches to each example method.
To run the examples:
Navigate to the Examples directory and open GroupDocs.Merger.Examples.CSharp.sln in your IDE (Visual Studio, JetBrains Rider, or Visual Studio Code with the C# extension).
Restore NuGet packages and build the solution. If references to GroupDocs.Merger are missing, see Installation.
Open RunExamples.cs, uncomment the example(s) you want to run, and comment out the rest.
Run the project. Output files are written to the location specified by each example.
Contribute
If you’d like to add or improve an example, we encourage you to contribute to the project. All examples in the repository are open source and can be freely used in your own applications.
To contribute, fork the repository, edit the code, and open a pull request. We will review the changes and include them if found helpful.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.