Skip to content

Commit dcbc771

Browse files
ES-263734-Changes added
1 parent 68eed7d commit dcbc771

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

  • Bookmarks/Rename-bookmark/.NET/Rename-bookmark

Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,19 @@ private static void ReplaceBookmarkName(WordDocument document, string existingbo
4040
return;
4141
//Gets owner paragraph of the bookmark
4242
WParagraph bookmarkStartParagraph = bookmark.BookmarkStart.Owner as WParagraph;
43-
//Gets index of the bookmark start and end
43+
//Gets index of the bookmark start
4444
int boomarkStartIndex = bookmarkStartParagraph.ChildEntities.IndexOf(bookmark.BookmarkStart);
45-
int boomarkEndIndex = 0;
4645
//Gets bookmark end paragraph
4746
WParagraph bookmarkEndParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
48-
//Checks whether the bookmark start and end is in same paragraph
49-
if (bookmarkEndParagraph == bookmarkStartParagraph)
50-
boomarkEndIndex = bookmarkStartParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
51-
else
52-
boomarkEndIndex = bookmarkEndParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
47+
//Gets index of the bookmark end
48+
int boomarkEndIndex = bookmarkEndParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
5349
//Removes the bookmark from Word document.
5450
document.Bookmarks.Remove(bookmark);
55-
//Inserts new bookmark in place of deleted bookmark
51+
//Inserts new bookmark start in place of deleted bookmark
5652
bookmarkStartParagraph.ChildEntities.Insert(boomarkStartIndex, bookmarkStartParagraph.AppendBookmarkStart(replaceBookmarkName));
57-
//Inserts bookmark end in corresponding paragraph.
58-
if (bookmarkEndParagraph == bookmarkStartParagraph)
59-
bookmarkStartParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkStartParagraph.AppendBookmarkEnd(replaceBookmarkName));
60-
else
61-
bookmarkEndParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkEndParagraph.AppendBookmarkEnd(replaceBookmarkName));
53+
//Inserts bookmark end in place of deleted bookmark
54+
bookmarkEndParagraph.ChildEntities.Insert(boomarkEndIndex, bookmarkEndParagraph.AppendBookmarkEnd(replaceBookmarkName));
55+
6256
}
6357
#endregion
6458
}

0 commit comments

Comments
 (0)