Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge–multiple-Word-files-in-same-page", "Merge–multiple-Word-files-in-same-page\Merge–multiple-Word-files-in-same-page.csproj", "{C790F761-62BA-49E1-8FF6-E15165CB08C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F533289D-7351-4DA3-96EE-B9C18CA8DCDD}
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Merge_multiple_Word_files_in_same_page</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.NET" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.Runtime.Serialization;

//Get the list of source document to be imported
List<string> sourceFileNames = new List<string>();
sourceFileNames.Add("../../../Data/Addressblock.docx");
sourceFileNames.Add("../../../Data/Salutation.docx");
sourceFileNames.Add("../../../Data/Greetings.docx");

string destinationFileName = "../../../Data/Title.docx";
using (FileStream destinationStreamPath = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens the destination document
using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic))
{
ImportOtherDocuments(sourceFileNames, destinationDocument);
//Saves and closes the destination document
using (FileStream outputStream = new FileStream("../../../Data/Output.docx", FileMode.Create, FileAccess.Write))
{
destinationDocument.Save(outputStream, FormatType.Docx);
destinationDocument.Close();
}
}
}

void ImportOtherDocuments(List<string> sourceFiles, WordDocument destinationDocument)
{
//Iterate through each source document from the list
foreach (string sourceFileName in sourceFiles)
{
//Open source document
using (FileStream sourceStreamPath = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic))
{
//Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
document.LastSection.BreakCode = SectionBreakCode.NoBreak;
//Imports the contents of source document at the end of destination document
destinationDocument.ImportContent(document, ImportOptions.UseDestinationStyles);
//Close the document.
document.Close();
}
}
}
}