What’s the best way to get all parent nodes of a node - I need to check a document & see if a bookmark is within a table?
Hi Melissa,
Thanks for your inquiry. I think in your case you can use Node.GetAncestor method. For example the following code checks if the bookmark is in a table.
// Open document.
Document doc = new Document(@“Test001\in.doc”);
// Get some bookmark.
Bookmark bk = doc.Range.Bookmarks[“bk2”];
// Get bk ancestor ot Table type.
Node tableAncestor = bk.BookmarkStart.GetAncestor(NodeType.Table);
// If ancestor of Table type is not null, the bookmark is inside table.
bool isInTable = tableAncestor != null;
Hope this helps.
Best regards,