diff --git a/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control.sln b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control.sln new file mode 100644 index 00000000..58295aee --- /dev/null +++ b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insert-content-into-block-content-control", "Insert-content-into-block-content-control\Insert-content-into-block-content-control.csproj", "{AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2D02C5F8-31E9-4F9E-96E9-D370D58B7826} + EndGlobalSection +EndGlobal diff --git a/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Data/Template.docx b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Data/Template.docx new file mode 100644 index 00000000..c2eb0db1 Binary files /dev/null and b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Data/Template.docx differ diff --git a/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Insert-content-into-block-content-control.csproj b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Insert-content-into-block-content-control.csproj new file mode 100644 index 00000000..b047bf3b --- /dev/null +++ b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Insert-content-into-block-content-control.csproj @@ -0,0 +1,22 @@ + + + + Exe + net8.0 + Insert_Word_document_in_block_content_control + + + + + + + + + Always + + + Always + + + + diff --git a/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Output/.gitkeep b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Program.cs b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Program.cs new file mode 100644 index 00000000..0a321ed2 --- /dev/null +++ b/Content-Controls/Insert-content-into-block-content-control/Insert-content-into-block-content-control/Program.cs @@ -0,0 +1,40 @@ +using System.IO; +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +// Creates a new Word document. +using (WordDocument document = new WordDocument()) +{ + // Adds new section to the document. + IWSection section = document.AddSection(); + WTextBody textBody = section.Body; + // Adds block content control into Word document. + BlockContentControl blockContentControl = textBody.AddBlockContentControl(ContentControlType.RichText) as BlockContentControl; + using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read)) + { + // Open the template Word document. + using (WordDocument docxDocument = new WordDocument(docStream, FormatType.Docx)) + { + // Insert the Word document into block content control. + InsertContentIntoBlockContentControl(blockContentControl, docxDocument); + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + // Saves the Word document. + document.Save(outputFileStream, FormatType.Docx); + } + } + } +} + +/// +/// Inserts the content of a specified Word document into a block content control. +/// +void InsertContentIntoBlockContentControl(BlockContentControl blockContentControl, WordDocument document) +{ + // Get the textbody of the another Word document and add it to the block content control. + WTextBody textBody = document.LastSection.Body; + foreach (IEntity entity in textBody.ChildEntities) + { + blockContentControl.TextBody.ChildEntities.Add(entity.Clone()); + } +} \ No newline at end of file