Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -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<Entity> 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<Entity> 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);
}
}
}
}
}
}
Loading