Thanks for your inquiry. In your case you should move DocumentBuilder cursor before bookmark. You should just use another overload of MoveToBookmark method: https://reference.aspose.com/words/net/aspose.words/documentbuilder/movetobookmark/
If you insert SectionBreak before bookmark, you will be able to identify section, which you need to remove by this bookmark. Here is sample code to insert section break right before bookmark:
Document doc = new Document(@"Test001\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// Move builder cursor before bookmark.
builder.MoveToBookmark("test", true, false);
// Insert section break.
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Save output document
doc.Save(@"Test001\out.doc");
And here is code to remove section with bookmark.
Document doc = new Document(@"Test001\out.doc");
// Get bookmark
Bookmark bk = doc.Range.Bookmarks["test"];
if (bk != null)
{
// remove section where this bookmark is located.
bk.BookmarkStart.GetAncestor(NodeType.Section).Remove();
}
// Save output document.
doc.Save(@"Test001\out1.doc");
Hi, thank you for your help,
but I don’t want to delete the bookmark beause I want to re-use it.
So I need to insert the section after the bookmark and then retrieve it and delete it.
Best regards
Thank you for additional information. In this case, you should insert section break after the bookmark. And then remove Section which follows the Section where bookmark is located.
Best regards.
Hi, How can I insert a new bookmark into the section create before ?
builder.insertbreak(BreakType.SectionBreakNewPage);
// Here insert a new bookmark
// And then I want to insert nodes at this location
Builber.insertNode(node);