Skip to content

Commit bc4193c

Browse files
author
sneha.biju
committed
Merge–multiple-Word-files-in-same-page sample added
1 parent 2882e86 commit bc4193c

File tree

7 files changed

+86
-0
lines changed

7 files changed

+86
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34322.80
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
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}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C790F761-62BA-49E1-8FF6-E15165CB08C1}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {F533289D-7351-4DA3-96EE-B9C18CA8DCDD}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Merge_multiple_Word_files_in_same_page</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.NET" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using System.Runtime.Serialization;
4+
5+
//Get the list of source document to be imported
6+
List<string> sourceFileNames = new List<string>();
7+
sourceFileNames.Add("../../../Data/Addressblock.docx");
8+
sourceFileNames.Add("../../../Data/Salutation.docx");
9+
sourceFileNames.Add("../../../Data/Greetings.docx");
10+
11+
string destinationFileName = "../../../Data/Title.docx";
12+
using (FileStream destinationStreamPath = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
13+
{
14+
//Opens the destination document
15+
using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic))
16+
{
17+
ImportOtherDocuments(sourceFileNames, destinationDocument);
18+
//Saves and closes the destination document
19+
using (FileStream outputStream = new FileStream("../../../Data/Output.docx", FileMode.Create, FileAccess.Write))
20+
{
21+
destinationDocument.Save(outputStream, FormatType.Docx);
22+
destinationDocument.Close();
23+
}
24+
}
25+
}
26+
27+
void ImportOtherDocuments(List<string> sourceFiles, WordDocument destinationDocument)
28+
{
29+
//Iterate through each source document from the list
30+
foreach (string sourceFileName in sourceFiles)
31+
{
32+
//Open source document
33+
using (FileStream sourceStreamPath = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
34+
{
35+
using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic))
36+
{
37+
//Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
38+
document.LastSection.BreakCode = SectionBreakCode.NoBreak;
39+
//Imports the contents of source document at the end of destination document
40+
destinationDocument.ImportContent(document, ImportOptions.UseDestinationStyles);
41+
//Close the document.
42+
document.Close();
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)