diff --git a/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer.sln b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer.sln new file mode 100644 index 00000000..7bc335d9 --- /dev/null +++ b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37614.0 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge-Documents-At-Bookmark-Without-Header-Footer", "Merge-Documents-At-Bookmark-Without-Header-Footer\Merge-Documents-At-Bookmark-Without-Header-Footer.csproj", "{FB3D4F30-E961-D224-3D61-28B0F1558896}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FB3D4F30-E961-D224-3D61-28B0F1558896}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB3D4F30-E961-D224-3D61-28B0F1558896}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB3D4F30-E961-D224-3D61-28B0F1558896}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB3D4F30-E961-D224-3D61-28B0F1558896}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F7241591-498A-45D3-987A-67EC1A189B3C} + EndGlobalSection +EndGlobal diff --git a/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Data/DestinationDocument.docx b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Data/DestinationDocument.docx new file mode 100644 index 00000000..73340949 Binary files /dev/null and b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Data/DestinationDocument.docx differ diff --git a/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Data/SourceDocument.docx b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Data/SourceDocument.docx new file mode 100644 index 00000000..d9b70897 Binary files /dev/null and b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Data/SourceDocument.docx differ diff --git a/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Merge-Documents-At-Bookmark-Without-Header-Footer.csproj b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Merge-Documents-At-Bookmark-Without-Header-Footer.csproj new file mode 100644 index 00000000..d1278484 --- /dev/null +++ b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Merge-Documents-At-Bookmark-Without-Header-Footer.csproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + Merge_Documents_At_Bookmark_Without_Header_Footer + + + + + Always + + + Always + + + Always + + + + + + + + + + diff --git a/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Output/.gitkeep b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Output/Output.docx b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Output/Output.docx new file mode 100644 index 00000000..445a3a0c Binary files /dev/null and b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Output/Output.docx differ diff --git a/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Program.cs b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Program.cs new file mode 100644 index 00000000..ed0ba919 --- /dev/null +++ b/Sections/Merge-Documents-At-Bookmark-Without-Header-Footer/.NET/Merge-Documents-At-Bookmark-Without-Header-Footer/Program.cs @@ -0,0 +1,63 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.IO; + +namespace Merge_Documents_At_Bookmark_Without_Header_Footer +{ + class Program + { + static void Main(string[] args) + { + //Load the destination Word document as a stream. +            using (FileStream destinationStreamPath = new FileStream(Path.GetFullPath(@"Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { +                //Open the destination Word document. +                using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic)) + { + //Load the source Word document as a stream. + using (FileStream sourceDocumentPathStream = new FileStream(Path.GetFullPath(@"Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Open the source Word document. + using (WordDocument sourceDocument = new WordDocument(sourceDocumentPathStream, FormatType.Docx)) + { + //Iterate source Word document sections. + foreach (WSection sourceDocumentSection in sourceDocument.Sections) + { + //Remove the first page header. + sourceDocumentSection.HeadersFooters.FirstPageHeader.ChildEntities.Clear(); + //Remove the first page footer. + sourceDocumentSection.HeadersFooters.FirstPageFooter.ChildEntities.Clear(); + //Remove the even header. + sourceDocumentSection.HeadersFooters.EvenHeader.ChildEntities.Clear(); + //Remove the even footer. + sourceDocumentSection.HeadersFooters.EvenFooter.ChildEntities.Clear(); + //Remove the odd header. + sourceDocumentSection.HeadersFooters.OddHeader.ChildEntities.Clear(); + //Remove the odd footer. + sourceDocumentSection.HeadersFooters.OddFooter.ChildEntities.Clear(); + } + //Get all the content as word document part + WordDocumentPart documentPart = new WordDocumentPart(sourceDocument); + //To maintain source document formattings + destinationDocument.ImportOptions = ImportOptions.KeepSourceFormatting; + //Create the bookmark navigator instance to access the bookmark. + BookmarksNavigator bkmkNavigator = new BookmarksNavigator(destinationDocument); + //Move the virtual cursor to the location before the end of the bookmark "MergeDocument". + bkmkNavigator.MoveToBookmark("MergeDocument"); + //Replace the bookmark content with Word document part. + bkmkNavigator.ReplaceContent(documentPart); + //Remove the bookmark in the merged document + destinationDocument.Bookmarks.Remove(bkmkNavigator.CurrentBookmark); + } + } +                    //Create a file stream. +                    using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Sample.docx"), FileMode.Create, FileAccess.ReadWrite)) + { +                        //Save the Word document to the file stream. +                        destinationDocument.Save(outputFileStream, FormatType.Docx); + } + } + } + } + } +}