Skip to content

Commit 2bace2d

Browse files
Added sample
1 parent 122d5fe commit 2bace2d

6 files changed

Lines changed: 85 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}") = "Remove_Field_ReferenceLinks", "Remove_Field_ReferenceLinks\Remove_Field_ReferenceLinks.csproj", "{B6C63866-67F8-3CB8-F517-6EB1FC20E12E}"
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+
{B6C63866-67F8-3CB8-F517-6EB1FC20E12E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B6C63866-67F8-3CB8-F517-6EB1FC20E12E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B6C63866-67F8-3CB8-F517-6EB1FC20E12E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B6C63866-67F8-3CB8-F517-6EB1FC20E12E}.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 = {24D6371E-D6B4-441F-8C1D-66D4E03D6860}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
4+
5+
namespace Remove_Field_ReferenceLink
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
// Open the template Word document.
12+
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"../../../Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite))
13+
{
14+
//Loads an existing Word document into DocIO instance.
15+
using (WordDocument document = new WordDocument(fileStream, FormatType.Automatic))
16+
{
17+
//Get all reference fields present in a document.
18+
List<Entity> fields = document.FindAllItemsByProperty(EntityType.Field, "FieldType", FieldType.FieldRef.ToString());
19+
//Unlink all ref fields.
20+
for (int i = 0; i < fields.Count; i++)
21+
{
22+
WField field = (WField)fields[i];
23+
if (field.Owner != null)
24+
field.Unlink();
25+
}
26+
//Creates file stream.
27+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
28+
{
29+
//Saves the Word document to file stream.
30+
document.Save(outputStream, FormatType.Docx);
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}
Lines changed: 23 additions & 0 deletions
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>

0 commit comments

Comments
 (0)