Skip to content

Commit 701b0bf

Browse files
642301-Find-and-replace-image-by-title
1 parent 73db5a3 commit 701b0bf

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed
Lines changed: 22 additions & 0 deletions
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-and-replace-image-by-title", "Find-and-replace-image-by-title\Find-and-replace-image-by-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,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Find_and_replace_image_by_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="Data\Template1.docx">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Output\.gitkeep">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>
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+
namespace Find_and_replace_image_by_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 Cycles") 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)