We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Delete a Section

I have a document that conatins bookmark, and I want to insert a section in a specif bookmark.
So I do:


Then I save the document.
How can I do to delete this Section in a second time ?


Thanks for your inquiry. In your case you should move DocumentBuilder cursor before bookmark. You should just use another overload of MoveToBookmark method:
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.
// Save output document

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.
// Save output document.

Hope this helps.
Best regards.

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 ?

// Here insert a new bookmark
// And then I want to insert nodes at this location

Best regard


Thanks for your inquiry. Of course, you can. You can use the following code to insert bookmark:

string bkName = "myBk";

But you should note, MS Word document cannot contain few bookmarks with the same name.
Best regards.