diff --git a/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document.sln b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document.sln new file mode 100644 index 00000000..9e845a88 --- /dev/null +++ b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37216.2 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find_a_Checkbox_in_a_Word_Document", "Find_a_Checkbox_in_a_Word_Document\Find_a_Checkbox_in_a_Word_Document.csproj", "{E634BF44-BF95-2A97-0C1A-21DA88BC1470}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E634BF44-BF95-2A97-0C1A-21DA88BC1470}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E634BF44-BF95-2A97-0C1A-21DA88BC1470}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E634BF44-BF95-2A97-0C1A-21DA88BC1470}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E634BF44-BF95-2A97-0C1A-21DA88BC1470}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C2B1D189-08D9-44F0-B768-9510ED36BD36} + EndGlobalSection +EndGlobal diff --git a/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Data/Template.docx b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Data/Template.docx new file mode 100644 index 00000000..d0e50ae7 Binary files /dev/null and b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Data/Template.docx differ diff --git a/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Find_a_Checkbox_in_a_Word_Document.csproj b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Find_a_Checkbox_in_a_Word_Document.csproj new file mode 100644 index 00000000..8d46b05c --- /dev/null +++ b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Find_a_Checkbox_in_a_Word_Document.csproj @@ -0,0 +1,23 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Output/Result.docx b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Output/Result.docx new file mode 100644 index 00000000..32055276 Binary files /dev/null and b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Output/Result.docx differ diff --git a/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Output/gitkeep.txt b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Output/gitkeep.txt new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Output/gitkeep.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Program.cs b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Program.cs new file mode 100644 index 00000000..7e79da37 --- /dev/null +++ b/Paragraphs/Find_a_Checkbox_in_a_Word_Document/.NET/Find_a_Checkbox_in_a_Word_Document/Program.cs @@ -0,0 +1,56 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +namespace Find_a_Checkbox_in_a_Word_Document +{ + class Program + { + static void Main(string[] args) + { + // Opens the input Word document from the specified path + using (FileStream fileStream = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.Read)) + { + // Loads the Word document into DocIO + using (WordDocument document = new WordDocument(fileStream, FormatType.Docx)) + { + // Finds all Block Content Controls of type CheckBox in the document + List blockContentControls = document.FindAllItemsByProperty(EntityType.BlockContentControl, "ContentControlProperties.Type", ContentControlType.CheckBox.ToString()); + + // Verifies if any block-level checkbox content controls are found + if (blockContentControls != null) + { + foreach (Entity entity in blockContentControls) + { + // Cast the entity to BlockContentControl + BlockContentControl blockContentControl = entity as BlockContentControl; + // Unchecks the checkbox + blockContentControl.ContentControlProperties.IsChecked = false; + } + } + + // Finds all Inline Content Controls of type CheckBox in the document + List inlineContentControls = document.FindAllItemsByProperty(EntityType.InlineContentControl, "ContentControlProperties.Type", ContentControlType.CheckBox.ToString()); + + // Verifies if any inline checkbox content controls are found + if (inlineContentControls != null) + { + foreach (Entity entity in inlineContentControls) + { + // Cast the entity to InlineContentControl + InlineContentControl inlineContentControl = entity as InlineContentControl; + // Unchecks the checkbox + inlineContentControl.ContentControlProperties.IsChecked = false; + } + } + + // Creates a file stream for the output document + using (FileStream outputStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write)) + { + // Saves the modified document with updated checkbox states + document.Save(outputStream, FormatType.Docx); + } + } + } + } + } +}