Skip to content

Commit 1aa7462

Browse files
ES-820647-Unlink-all-fields-in-Word-document
1 parent 9c8fa2d commit 1aa7462

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed
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 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unlink-all-fields-in-Word-document", "Unlink-all-fields-in-Word-document\Unlink-all-fields-in-Word-document.csproj", "{D3AF529E-DB54-4294-A876-DD42E1E472D0}"
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+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.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 = {58137FF9-5AE1-4514-9929-3A8A7DA1DFEB}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.DocIORenderer;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
7+
namespace Unlink_all_fields_in_Word_document
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite))
14+
{
15+
//Loads an existing Word document into DocIO instance.
16+
using (WordDocument document = new WordDocument(fileStream, FormatType.Automatic))
17+
{
18+
//Updates the fields present in a document
19+
document.UpdateDocumentFields(true);
20+
21+
//Get all fields present in a document.
22+
List<Entity> fields = document.FindAllItemsByProperty(EntityType.Field, null, null);
23+
24+
//Unlink all the fields.
25+
for (int i = 0; i < fields.Count; i++)
26+
{
27+
WField field = (WField)fields[i];
28+
if (field.Owner != null)
29+
field.Unlink();
30+
}
31+
32+
//Creates file stream.
33+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
34+
{
35+
//Saves the Word document to file stream.
36+
document.Save(outputStream, FormatType.Docx);
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Unlink_all_fields_in_Word_document</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Template.docx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>

0 commit comments

Comments
 (0)