diff --git a/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page.sln b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page.sln new file mode 100644 index 000000000..5525973fc --- /dev/null +++ b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35527.113 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Preserve-merged-documents-in-new-page", "Preserve-merged-documents-in-new-page\Preserve-merged-documents-in-new-page.csproj", "{5E219324-70AF-4788-A3F7-82260DCCE746}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5E219324-70AF-4788-A3F7-82260DCCE746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5E219324-70AF-4788-A3F7-82260DCCE746}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5E219324-70AF-4788-A3F7-82260DCCE746}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5E219324-70AF-4788-A3F7-82260DCCE746}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Data/DestinationDocument.docx b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Data/DestinationDocument.docx new file mode 100644 index 000000000..fbaf361a4 Binary files /dev/null and b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Data/DestinationDocument.docx differ diff --git a/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Data/SourceDocument.docx b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Data/SourceDocument.docx new file mode 100644 index 000000000..76bce7792 Binary files /dev/null and b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Data/SourceDocument.docx differ diff --git a/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Output/.gitkeep b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Preserve-merged-documents-in-new-page.csproj b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Preserve-merged-documents-in-new-page.csproj new file mode 100644 index 000000000..dcedef5d1 --- /dev/null +++ b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Preserve-merged-documents-in-new-page.csproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + Preserve_merged_documents_in_new_page + enable + enable + + + + + + + + + Always + + + Always + + + Always + + + + diff --git a/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Program.cs b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Program.cs new file mode 100644 index 000000000..15f37cdf8 --- /dev/null +++ b/Word-document/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Program.cs @@ -0,0 +1,38 @@ +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIO; +using System.Reflection.Metadata; + +namespace Preserve_merged_documents_in_new_page +{ + internal class Program + { + static void Main(string[] args) + { + using (FileStream sourceStreamPath = new FileStream(Path.GetFullPath(@"Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Opens an source document from file system through constructor of WordDocument class. + using (WordDocument sourceDocument = new WordDocument(sourceStreamPath, FormatType.Automatic)) + { + using (FileStream destinationStreamPath = new FileStream(Path.GetFullPath(@"Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Opens the destination document. + using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic)) + { + //Sets the break-code of first section of source document + sourceDocument.Sections[0].BreakCode = SectionBreakCode.NewPage; + //Imports the contents of the source document to the destination document, and + //applies the formatting of surrounding content to the destination document. + destinationDocument.ImportContent(sourceDocument, ImportOptions.MergeFormatting); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + destinationDocument.Save(outputFileStream, FormatType.Docx); + } + } + } + } + } + } + } +}