Skip to content

Commit cc4ad5d

Browse files
Merge pull request #277 from Suriya-Balamurugan/ES-899196-Get-URL-from-INCLUDEPICTURE
Added sample to retrieve the URL from an INCLUDEPICTURE field in a Word document
2 parents d7d3602 + b51c692 commit cc4ad5d

File tree

6 files changed

+109
-4
lines changed

6 files changed

+109
-4
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.30804.86
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Get-URL-from-INCLUDEPICTURE", "Get-URL-from-INCLUDEPICTURE/Get-URL-from-INCLUDEPICTURE.csproj", "{0134A925-CBCF-46F4-AB34-F4564DE2D824}"
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+
{0134A925-CBCF-46F4-AB34-F4564DE2D824}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0134A925-CBCF-46F4-AB34-F4564DE2D824}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0134A925-CBCF-46F4-AB34-F4564DE2D824}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0134A925-CBCF-46F4-AB34-F4564DE2D824}.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 = {EC1DEE95-A860-458D-AC10-B2677F41C019}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Get_URL_from_INCLUDEPICTURE</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Input.docx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using System.Collections.Generic;
4+
using System;
5+
using System.IO;
6+
using System.Linq;
7+
8+
namespace Get_URL_from_INCLUDEPICTURE
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
15+
{
16+
//Open an existing Word document into DocIO instance.
17+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
18+
{
19+
//Find all INCLUDEPICTURE fields in the Word document based on field type.
20+
List<Entity> IncludePictureFields = document.FindAllItemsByProperty(EntityType.Field, "FieldType", "FieldIncludePicture");
21+
//List to store extracted URLs.
22+
List<string> urls = new List<string>();
23+
//Iterate through all INCLUDEPICTURE fields found in the document.
24+
foreach (WField field in IncludePictureFields)
25+
{
26+
//Extract the field code.
27+
string fieldCode = field.FieldCode;
28+
//The field code is in the format: INCLUDEPICTURE "URL"
29+
//Extract the URL between the quotes.
30+
string url = ExtractUrlFromFieldCode(fieldCode);
31+
//Add the URL to the list.
32+
urls.Add(url);
33+
}
34+
//Print all URLs at the end.
35+
Console.WriteLine("INCLUDEPICTURE URLs:");
36+
foreach (string url in urls)
37+
{
38+
Console.WriteLine(url);
39+
}
40+
}
41+
}
42+
}
43+
#region Helper methods
44+
/// <summary>
45+
/// Extract the URL from the given INCLUDEPICTURE field code.
46+
/// </summary>
47+
/// <param name="fieldCode">The field code containing the URL.</param>
48+
/// <returns>The extracted URL as a string.</returns>
49+
static string ExtractUrlFromFieldCode(string fieldCode)
50+
{
51+
string url = string.Empty;
52+
//Find the starting index of the URL (after the first quote).
53+
int startIndex = fieldCode.IndexOf('"') + 1;
54+
//Find the ending index of the URL (before the last quote).
55+
int endIndex = fieldCode.LastIndexOf('"');
56+
//Ensure valid indices and extract the URL if valid.
57+
if (startIndex > 0 && endIndex > startIndex)
58+
{
59+
url = fieldCode.Substring(startIndex, endIndex - startIndex);
60+
}
61+
return url;
62+
}
63+
#endregion
64+
}
65+
}

Paragraphs/Get-heading-list-value/.NET/Get-heading-list-value/Get-heading-list-value.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
<None Update="Data\Template.docx">
1515
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1616
</None>
17-
<None Update="Output\.gitkeep">
18-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19-
</None>
2017
</ItemGroup>
2118

2219
</Project>

Paragraphs/Get-heading-list-value/.NET/Get-heading-list-value/Output/.gitkeep

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)