Find Content Controls between 2 Bookmarks only


How do I find structure document tags (content controls) after any given bookmark?

I have lots of headings in a word document which all have a bookmark and I want to search for content controls under a single heading only. I know how to search for them within a document and I know how to move to a bookmark, but I don’t know how to find content controls between 2 bookmarks.

In other words, I want to find all content controls that come after a specified bookmark (which I know the name of) and before any other bookmark (which I don’t know the name of) - so content controls in between 2 bookmarks, the first one whose name I know and the second one I don’t.



In your case, we suggest you following solution.

  1. Move the cursor to the bookmark.
  2. Use Node.NextPreOrder Method to get next node according to the pre-order tree traversal algorithm.
  3. Check the next node type either it is StructuredDocumentTag or not.
  4. If yes, get the content control Node.

Hope this helps you. If you still face problem, please ZIP and attach your input document and content control that you want to get. We will then provide you more information about your query along with code.


Great, thanks!