Skip to content

Commit 11e64fe

Browse files
Merge pull request #554 from SyncfusionExamples/992084-GetType
992084-How to Get the type and name of all the content controls used in document?
2 parents ea4f8f5 + 1e92215 commit 11e64fe

6 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.37216.2 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Get_Type_and_Name_of_ContentControls", "Get_Type_and_Name_of_ContentControls\Get_Type_and_Name_of_ContentControls.csproj", "{B61D400B-AAF4-4152-BCBB-CC1680154531}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B61D400B-AAF4-4152-BCBB-CC1680154531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B61D400B-AAF4-4152-BCBB-CC1680154531}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B61D400B-AAF4-4152-BCBB-CC1680154531}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B61D400B-AAF4-4152-BCBB-CC1680154531}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {EF68BA68-7A9D-4647-ACCB-6B559AFD62E0}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<None Update="Data\Template.docx">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
<None Update="Output\.gitkeep">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
namespace Get_Type_and_Name_of_ContentControls
5+
{
6+
class Program
7+
{
8+
9+
static void Main(string[] args)
10+
{
11+
using (FileStream docStream = new FileStream(@Path.GetFullPath(@"../../../Data/Template.docx"), FileMode.Open, FileAccess.Read))
12+
{
13+
//Load the file stream into a Word document
14+
using (WordDocument document = new WordDocument(docStream, FormatType.Docx))
15+
{
16+
//Find all block content controls
17+
List<Entity> blockContentControls = document.FindAllItemsByProperties(EntityType.BlockContentControl, null, null);
18+
19+
//Process block content controls
20+
foreach (BlockContentControl blockContentControl in blockContentControls)
21+
{
22+
//Access block content control properties
23+
string title = blockContentControl.ContentControlProperties.Title;
24+
string tag = blockContentControl.ContentControlProperties.Tag;
25+
Console.WriteLine("BlockContentControl Title: " + title + ", Tag: " + tag);
26+
}
27+
28+
//Find all inline content controls
29+
List<Entity> inlineContentControls = document.FindAllItemsByProperties(EntityType.InlineContentControl, null, null);
30+
31+
//Process inline content controls
32+
foreach (InlineContentControl inlineContentControl in inlineContentControls)
33+
{
34+
//Access inline content control properties
35+
string title = inlineContentControl.ContentControlProperties.Title;
36+
string tag = inlineContentControl.ContentControlProperties.Tag;
37+
Console.WriteLine("InlineContentControl Title: " + title + ", Tag: " + tag);
38+
}
39+
40+
//Save the modified document if needed
41+
using (FileStream outputStream = new FileStream(@Path.GetFullPath(@"../../../Output/Result.docx"), FileMode.Create, FileAccess.Write))
42+
{
43+
document.Save(outputStream, FormatType.Docx);
44+
}
45+
}
46+
}
47+
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)