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uz^-Txy<&h}-Y#>TI1Do^_FE}5w{
zJt~2jd#U%KDZ5iekN72=CnLKR=s$s
zhlp)*Ha;9OFP1bnU1o
zEg&>AFc<*yCBAbP&`m<$PmeHb3UJ9V=I(lQ{pkCe5&C_A8%DwUk#{+xYe(N;iqOs^
z4AqXb-4tCn`pRa6?&At5y20z5(RHIwxg&Jv=s|U(Pr#!afj$|CFhbM_Y6SAsAi8$+
zQGA5<*=8{9@G*UK&FJlGgl0QusAja*Ho6JuEl7k3^IV`NqybO7gSRKq^`ka35V{!{
rcDgYzU^F_=wWC%R$l8rOk+egrjsR~~V9o%|cJMRo0cNiI-XI
+ /// Replace bookmark name
+ ///
+ /// Input Word document.
+ /// The name of the bookmark to replace.
+ /// The new name for the bookmark.
+
+ private static void ReplaceBookmarkName(WordDocument document, string existingbookmarkName, string replaceBookmarkName)
+ {
+ //Gets the bookmark instance by using FindByName method of BookmarkCollection with bookmark name
+ Bookmark bookmark = document.Bookmarks.FindByName(existingbookmarkName);
+ // No bookmark found, return immediately
+ if (bookmark == null)
+ return;
+ //Gets owner paragraph of the bookmark
+ WParagraph bookmarkStartParagraph = bookmark.BookmarkStart.Owner as WParagraph;
+ //Gets index of the bookmark start and end
+ int boomarkStartIndex = bookmarkStartParagraph.ChildEntities.IndexOf(bookmark.BookmarkStart);
+ int boomarkEndIndex = 0;
+ //Gets bookmark end paragraph
+ WParagraph bookmarkEndParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
+ //Checks whether the bookmark start and end is in same paragraph
+ if (bookmarkEndParagraph == bookmarkStartParagraph)
+ boomarkEndIndex = bookmarkStartParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
+ else
+ boomarkEndIndex = bookmarkEndParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
+ //Removes the bookmark from Word document.
+ document.Bookmarks.Remove(bookmark);
+ //Inserts new bookmark in place of deleted bookmark
+ bookmarkStartParagraph.ChildEntities.Insert(boomarkStartIndex, bookmarkStartParagraph.AppendBookmarkStart(replaceBookmarkName));
+ //Inserts bookmark end in corresponding paragraph.
+ if (bookmarkEndParagraph == bookmarkStartParagraph)
+ bookmarkStartParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkStartParagraph.AppendBookmarkEnd(replaceBookmarkName));
+ else
+ bookmarkEndParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkEndParagraph.AppendBookmarkEnd(replaceBookmarkName));
+ }
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Rename-bookmark.csproj b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Rename-bookmark.csproj
new file mode 100644
index 000000000..b2138abbe
--- /dev/null
+++ b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Rename-bookmark.csproj
@@ -0,0 +1,24 @@
+
+
+
+ Exe
+ net8.0
+ Rename_bookmark
+ enable
+ enable
+
+
+
+
+
+
+
+
+ Always
+
+
+ Always
+
+
+
+
From dcbc7716d326369a96242431e07257871b4bbd0b Mon Sep 17 00:00:00 2001
From: Kathiresan4347 <159137198+Kathiresan4347@users.noreply.github.com>
Date: Mon, 5 Jan 2026 15:41:10 +0530
Subject: [PATCH 2/6] ES-263734-Changes added
---
.../.NET/Rename-bookmark/Program.cs | 20 +++++++------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
index d47747f06..d3b1181de 100644
--- a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
+++ b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
@@ -40,25 +40,19 @@ private static void ReplaceBookmarkName(WordDocument document, string existingbo
return;
//Gets owner paragraph of the bookmark
WParagraph bookmarkStartParagraph = bookmark.BookmarkStart.Owner as WParagraph;
- //Gets index of the bookmark start and end
+ //Gets index of the bookmark start
int boomarkStartIndex = bookmarkStartParagraph.ChildEntities.IndexOf(bookmark.BookmarkStart);
- int boomarkEndIndex = 0;
//Gets bookmark end paragraph
WParagraph bookmarkEndParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
- //Checks whether the bookmark start and end is in same paragraph
- if (bookmarkEndParagraph == bookmarkStartParagraph)
- boomarkEndIndex = bookmarkStartParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
- else
- boomarkEndIndex = bookmarkEndParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
+ //Gets index of the bookmark end
+ int boomarkEndIndex = bookmarkEndParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
//Removes the bookmark from Word document.
document.Bookmarks.Remove(bookmark);
- //Inserts new bookmark in place of deleted bookmark
+ //Inserts new bookmark start in place of deleted bookmark
bookmarkStartParagraph.ChildEntities.Insert(boomarkStartIndex, bookmarkStartParagraph.AppendBookmarkStart(replaceBookmarkName));
- //Inserts bookmark end in corresponding paragraph.
- if (bookmarkEndParagraph == bookmarkStartParagraph)
- bookmarkStartParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkStartParagraph.AppendBookmarkEnd(replaceBookmarkName));
- else
- bookmarkEndParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkEndParagraph.AppendBookmarkEnd(replaceBookmarkName));
+ //Inserts bookmark end in place of deleted bookmark
+ bookmarkEndParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkEndParagraph.AppendBookmarkEnd(replaceBookmarkName));
+
}
#endregion
}
From 9652fcd621c6eebb2c7b2b6052fc8be41340323a Mon Sep 17 00:00:00 2001
From: Kathiresan4347 <159137198+Kathiresan4347@users.noreply.github.com>
Date: Tue, 6 Jan 2026 18:50:28 +0530
Subject: [PATCH 3/6] ES-263734-Changes added
---
.../.NET/Rename-bookmark/Program.cs | 69 ++++++++++++++-----
1 file changed, 51 insertions(+), 18 deletions(-)
diff --git a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
index d3b1181de..d0cc06f68 100644
--- a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
+++ b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
@@ -15,7 +15,7 @@ static void Main(string[] args)
//Replace Bookmark name
ReplaceBookmarkName(document, "Northwind", "New_Bookmark");
//Creates file stream.
- using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite))
+ using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Docx);
@@ -28,31 +28,64 @@ static void Main(string[] args)
/// Replace bookmark name
///
/// Input Word document.
- /// The name of the bookmark to replace.
+ /// The name of the bookmark to replace.
/// The new name for the bookmark.
-
- private static void ReplaceBookmarkName(WordDocument document, string existingbookmarkName, string replaceBookmarkName)
+ private static void ReplaceBookmarkName(WordDocument document, string existingBookmarkName, string replaceBookmarkName)
{
//Gets the bookmark instance by using FindByName method of BookmarkCollection with bookmark name
- Bookmark bookmark = document.Bookmarks.FindByName(existingbookmarkName);
+ Bookmark bookmark = document.Bookmarks.FindByName(existingBookmarkName);
// No bookmark found, return immediately
if (bookmark == null)
return;
- //Gets owner paragraph of the bookmark
- WParagraph bookmarkStartParagraph = bookmark.BookmarkStart.Owner as WParagraph;
- //Gets index of the bookmark start
- int boomarkStartIndex = bookmarkStartParagraph.ChildEntities.IndexOf(bookmark.BookmarkStart);
- //Gets bookmark end paragraph
- WParagraph bookmarkEndParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
- //Gets index of the bookmark end
- int boomarkEndIndex = bookmarkEndParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
+ // Variables for owner entity start and end positions
+ WParagraph startParagraph = null;
+ InlineContentControl startICC = null;
+ int startIndex = -1;
+
+ WParagraph endParagraph = null;
+ InlineContentControl endICC = null;
+ int endIndex = -1;
+ // Determine the owner and index for the bookmark start.
+ // The bookmark start may be inside a WParagraph (as a child entity)
+ // or inside an InlineContentControl (as a paragraph item).
+ if (bookmark.BookmarkStart != null && bookmark.BookmarkStart.Owner is WParagraph)
+ {
+ startParagraph = bookmark.BookmarkStart.Owner as WParagraph;
+ startIndex = startParagraph.ChildEntities.IndexOf(bookmark.BookmarkStart);
+ }
+ else if (bookmark.BookmarkStart != null && bookmark.BookmarkStart.Owner is InlineContentControl)
+ {
+ startICC = bookmark.BookmarkStart.Owner as InlineContentControl;
+ startIndex = startICC.ParagraphItems.IndexOf(bookmark.BookmarkStart);
+ }
+ // Determine the owner and index for the bookmark end.
+ // Similar to start, the end could be in a paragraph or inline content contro
+ if (bookmark.BookmarkEnd != null && bookmark.BookmarkEnd.Owner is WParagraph)
+ {
+ endParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
+ endIndex = endParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
+ }
+ else if (bookmark.BookmarkEnd != null && bookmark.BookmarkEnd.Owner is InlineContentControl)
+ {
+ endICC = bookmark.BookmarkEnd.Owner as InlineContentControl;
+ endIndex = endICC.ParagraphItems.IndexOf(bookmark.BookmarkEnd);
+ }
//Removes the bookmark from Word document.
document.Bookmarks.Remove(bookmark);
- //Inserts new bookmark start in place of deleted bookmark
- bookmarkStartParagraph.ChildEntities.Insert(boomarkStartIndex, bookmarkStartParagraph.AppendBookmarkStart(replaceBookmarkName));
- //Inserts bookmark end in place of deleted bookmark
- bookmarkEndParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkEndParagraph.AppendBookmarkEnd(replaceBookmarkName));
-
+ // Create a new BookmarkStart and insert at the recorded index.
+ BookmarkStart newBookmarkStart = new BookmarkStart(document, replaceBookmarkName);
+ // Insert new bookmark start at the original position with the new name.
+ if (startParagraph != null)
+ startParagraph.ChildEntities.Insert(startIndex, newBookmarkStart);
+ else if (startICC != null)
+ startICC.ParagraphItems.Insert(startIndex, newBookmarkStart);
+ // Create a new BookmarkEnd and insert at the recorded index.
+ BookmarkEnd newBookmarkEnd = new BookmarkEnd(document, replaceBookmarkName);
+ // Insert new bookmark end at the original position with the new name.
+ if (endParagraph != null)
+ endParagraph.ChildEntities.Insert(endIndex, newBookmarkEnd);
+ else if (endICC != null)
+ endICC.ParagraphItems.Insert(endIndex, newBookmarkEnd);
}
#endregion
}
From 09bbcdcd5dbe5f0bb9260286358727394ca795aa Mon Sep 17 00:00:00 2001
From: Kathiresan4347 <159137198+Kathiresan4347@users.noreply.github.com>
Date: Tue, 6 Jan 2026 19:48:18 +0530
Subject: [PATCH 4/6] ES-263734-Feedback addressed
---
.../.NET/Rename-bookmark/Program.cs | 51 ++++++++++---------
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
index d0cc06f68..5eca1e8f0 100644
--- a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
+++ b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
@@ -37,55 +37,56 @@ private static void ReplaceBookmarkName(WordDocument document, string existingBo
// No bookmark found, return immediately
if (bookmark == null)
return;
- // Variables for owner entity start and end positions
- WParagraph startParagraph = null;
- InlineContentControl startICC = null;
+ //Variable for store index of bookmark start and end
int startIndex = -1;
-
- WParagraph endParagraph = null;
- InlineContentControl endICC = null;
int endIndex = -1;
+ // Creating new bookmark with the replacement name
+ BookmarkStart newBookmarkStart = new BookmarkStart(document, replaceBookmarkName);
+ BookmarkEnd newBookmarkEnd = new BookmarkEnd(document, replaceBookmarkName);
+
// Determine the owner and index for the bookmark start.
// The bookmark start may be inside a WParagraph (as a child entity)
// or inside an InlineContentControl (as a paragraph item).
if (bookmark.BookmarkStart != null && bookmark.BookmarkStart.Owner is WParagraph)
{
- startParagraph = bookmark.BookmarkStart.Owner as WParagraph;
+ WParagraph startParagraph = bookmark.BookmarkStart.Owner as WParagraph;
+ // Find the index of the old bookmark start in the paragraph's child entities
startIndex = startParagraph.ChildEntities.IndexOf(bookmark.BookmarkStart);
+ // Insert the new bookmark end at the same index (if found)
+ if (startIndex >= 0)
+ startParagraph.ChildEntities.Insert(startIndex, newBookmarkStart);
}
else if (bookmark.BookmarkStart != null && bookmark.BookmarkStart.Owner is InlineContentControl)
{
- startICC = bookmark.BookmarkStart.Owner as InlineContentControl;
+ InlineContentControl startICC = bookmark.BookmarkStart.Owner as InlineContentControl;
+ // Find the index of the old bookmark end in the ICC's paragraph items
startIndex = startICC.ParagraphItems.IndexOf(bookmark.BookmarkStart);
+ // Insert the new bookmark end at the same index (if found)
+ if (startIndex >= 0)
+ startICC.ParagraphItems.Insert(startIndex, newBookmarkStart);
}
// Determine the owner and index for the bookmark end.
// Similar to start, the end could be in a paragraph or inline content contro
if (bookmark.BookmarkEnd != null && bookmark.BookmarkEnd.Owner is WParagraph)
{
- endParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
+ WParagraph endParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
+ // Find the index of the old bookmark end in the paragraph's child entities
endIndex = endParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
+ // Insert the new bookmark end at the same index (if found)
+ if (endIndex >= 0)
+ endParagraph.ChildEntities.Insert(endIndex, newBookmarkEnd);
}
else if (bookmark.BookmarkEnd != null && bookmark.BookmarkEnd.Owner is InlineContentControl)
{
- endICC = bookmark.BookmarkEnd.Owner as InlineContentControl;
+ InlineContentControl endICC = bookmark.BookmarkEnd.Owner as InlineContentControl;
+ // Find the index of the old bookmark end in the ICC's paragraph items
endIndex = endICC.ParagraphItems.IndexOf(bookmark.BookmarkEnd);
+ // Insert the new bookmark end at the same index (if found)
+ if (endIndex >= 0)
+ endICC.ParagraphItems.Insert(endIndex, newBookmarkEnd);
}
//Removes the bookmark from Word document.
- document.Bookmarks.Remove(bookmark);
- // Create a new BookmarkStart and insert at the recorded index.
- BookmarkStart newBookmarkStart = new BookmarkStart(document, replaceBookmarkName);
- // Insert new bookmark start at the original position with the new name.
- if (startParagraph != null)
- startParagraph.ChildEntities.Insert(startIndex, newBookmarkStart);
- else if (startICC != null)
- startICC.ParagraphItems.Insert(startIndex, newBookmarkStart);
- // Create a new BookmarkEnd and insert at the recorded index.
- BookmarkEnd newBookmarkEnd = new BookmarkEnd(document, replaceBookmarkName);
- // Insert new bookmark end at the original position with the new name.
- if (endParagraph != null)
- endParagraph.ChildEntities.Insert(endIndex, newBookmarkEnd);
- else if (endICC != null)
- endICC.ParagraphItems.Insert(endIndex, newBookmarkEnd);
+ document.Bookmarks.Remove(bookmark);
}
#endregion
}
From ac7c2ac53600d05f6876ee3e7769f6489e5344ea Mon Sep 17 00:00:00 2001
From: Kathiresan4347 <159137198+Kathiresan4347@users.noreply.github.com>
Date: Tue, 6 Jan 2026 19:54:59 +0530
Subject: [PATCH 5/6] ES-263734-Comments modified
---
Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
index 5eca1e8f0..9bccb2109 100644
--- a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
+++ b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
@@ -37,10 +37,10 @@ private static void ReplaceBookmarkName(WordDocument document, string existingBo
// No bookmark found, return immediately
if (bookmark == null)
return;
- //Variable for store index of bookmark start and end
+ // Variables to store the index positions of the bookmark start and end within their respective owners
int startIndex = -1;
int endIndex = -1;
- // Creating new bookmark with the replacement name
+ // Create new bookmark start and end markers with the replacement name
BookmarkStart newBookmarkStart = new BookmarkStart(document, replaceBookmarkName);
BookmarkEnd newBookmarkEnd = new BookmarkEnd(document, replaceBookmarkName);
@@ -66,7 +66,7 @@ private static void ReplaceBookmarkName(WordDocument document, string existingBo
startICC.ParagraphItems.Insert(startIndex, newBookmarkStart);
}
// Determine the owner and index for the bookmark end.
- // Similar to start, the end could be in a paragraph or inline content contro
+ // Similar to start, the end could be in a paragraph or inline content control.
if (bookmark.BookmarkEnd != null && bookmark.BookmarkEnd.Owner is WParagraph)
{
WParagraph endParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
From 2f74cb7a15fd35b935455e8e03f4d09dd0bfa93f Mon Sep 17 00:00:00 2001
From: Kathiresan4347 <159137198+Kathiresan4347@users.noreply.github.com>
Date: Tue, 6 Jan 2026 20:08:04 +0530
Subject: [PATCH 6/6] ES-263734-Feedback addressed
---
.../.NET/Rename-bookmark/Program.cs | 20 ++++++++-----------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
index 9bccb2109..64c357f99 100644
--- a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
+++ b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs
@@ -52,18 +52,16 @@ private static void ReplaceBookmarkName(WordDocument document, string existingBo
WParagraph startParagraph = bookmark.BookmarkStart.Owner as WParagraph;
// Find the index of the old bookmark start in the paragraph's child entities
startIndex = startParagraph.ChildEntities.IndexOf(bookmark.BookmarkStart);
- // Insert the new bookmark end at the same index (if found)
- if (startIndex >= 0)
- startParagraph.ChildEntities.Insert(startIndex, newBookmarkStart);
+ // Insert the new bookmark end at the same index.
+ startParagraph.ChildEntities.Insert(startIndex, newBookmarkStart);
}
else if (bookmark.BookmarkStart != null && bookmark.BookmarkStart.Owner is InlineContentControl)
{
InlineContentControl startICC = bookmark.BookmarkStart.Owner as InlineContentControl;
// Find the index of the old bookmark end in the ICC's paragraph items
startIndex = startICC.ParagraphItems.IndexOf(bookmark.BookmarkStart);
- // Insert the new bookmark end at the same index (if found)
- if (startIndex >= 0)
- startICC.ParagraphItems.Insert(startIndex, newBookmarkStart);
+ // Insert the new bookmark end at the same index.
+ startICC.ParagraphItems.Insert(startIndex, newBookmarkStart);
}
// Determine the owner and index for the bookmark end.
// Similar to start, the end could be in a paragraph or inline content control.
@@ -72,18 +70,16 @@ private static void ReplaceBookmarkName(WordDocument document, string existingBo
WParagraph endParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
// Find the index of the old bookmark end in the paragraph's child entities
endIndex = endParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
- // Insert the new bookmark end at the same index (if found)
- if (endIndex >= 0)
- endParagraph.ChildEntities.Insert(endIndex, newBookmarkEnd);
+ // Insert the new bookmark end at the same index.
+ endParagraph.ChildEntities.Insert(endIndex, newBookmarkEnd);
}
else if (bookmark.BookmarkEnd != null && bookmark.BookmarkEnd.Owner is InlineContentControl)
{
InlineContentControl endICC = bookmark.BookmarkEnd.Owner as InlineContentControl;
// Find the index of the old bookmark end in the ICC's paragraph items
endIndex = endICC.ParagraphItems.IndexOf(bookmark.BookmarkEnd);
- // Insert the new bookmark end at the same index (if found)
- if (endIndex >= 0)
- endICC.ParagraphItems.Insert(endIndex, newBookmarkEnd);
+ // Insert the new bookmark end at the same index.
+ endICC.ParagraphItems.Insert(endIndex, newBookmarkEnd);
}
//Removes the bookmark from Word document.
document.Bookmarks.Remove(bookmark);