Skip to content

Commit 4f71670

Browse files
Merge pull request #320 from SyncfusionExamples/642301-Find-and-replace-image-by-title
642301-Add the sample Find-and-replace-image-by-title in Find-item-in-word-document folder
2 parents 1f7b661 + 5310e19 commit 4f71670

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-image-by-title-and-replace-with-another-title", "Find-image-by-title-and-replace-with-another-title\Find-image-by-title-and-replace-with-another-title.csproj", "{ACC623F6-FE08-4247-BD74-E575D40EF8B3}"
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+
{ACC623F6-FE08-4247-BD74-E575D40EF8B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{ACC623F6-FE08-4247-BD74-E575D40EF8B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{ACC623F6-FE08-4247-BD74-E575D40EF8B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{ACC623F6-FE08-4247-BD74-E575D40EF8B3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Find_image_by_title_and_replace_with_another_title</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
4+
namespace Find_image_by_title_and_replace_with_another_title
5+
{
6+
internal class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
// Open the Word template document as a file stream.
11+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
12+
{
13+
// Open the Word document from the file stream.
14+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
15+
{
16+
// Find a picture in the document by its Title property.
17+
WPicture picture = document.FindItemByProperty(EntityType.Picture, "Title", "Adventure Works Cycle") as WPicture;
18+
19+
// If the picture is found, modify its Title property.
20+
if (picture != null)
21+
{
22+
// Change the Title of the found picture.
23+
picture.Title = "Mountain-200";
24+
}
25+
26+
// Create a file stream for saving the modified document.
27+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
28+
{
29+
// Save the modified Word document to the file stream in DOCX format.
30+
document.Save(outputFileStream, FormatType.Docx);
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)