I created regular bookmarks in a text file and converted them to a hidden bookmark pragmatically. As mentioned above, hidden bookmarks can only be created pragmatically, and their name is preceded by "_". Whenever a bookmark list is ever repeated, make sure Bookmarks.ShowHidden is set to true, otherwise hidden bookmarks will not appear in the list. Below is the code I used to hide all visible bookmarks. At the very end, I also clear the undo entry to make sure that the user cannot undo the changes I made. You can create a custom cancellation record, if you want, delete the last action.
public static void hideAllBookmark(Document doc) { String newName = null; Range newRange = null; bool backup = doc.Bookmarks.ShowHidden; doc.Bookmarks.ShowHidden = false; for (int i = doc.Bookmarks.Count; i > 0; i--) { if (!doc.Bookmarks[i].Name.Substring(0, 1).Equals("_", StringComparison.OrdinalIgnoreCase)) { newName= "_" + doc.Bookmarks[i].Name; newRange = doc.Bookmarks[i].Range; doc.Bookmarks[i].Delete(); doc.Bookmarks.Add(newName, newRange); } } doc.Bookmarks.ShowHidden = backup; doc.UndoClear(); }
Abhijit amin
source share