Aspose.word insert a paragraph right before a bookmark

Hello,

I’m trying to insert a paragraph right before a bookmark using the following code :

ParagraphBeforeBookmark.ParentNode.InsertAfter(NewParagraph, ParagraphBeforeBookmark);

This indeed inserts the new paragraph after the existing one but also after the bookmark.

I wanted to insert the new paragraph between the existing one and before the bookmark, how can i proceed ?

Edit : maybe i’m getting the wrong node, i tried to get the node preceeding my bookmark using the following code :

myBookmarkStart.PreviousPreOrder(myBookmarkStart)

Sincerely.

@guyyyyyyyyyyy I think the easiest way to achieve this is using DocumentBuilder:

Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

// Move document builder to the bookmark.
builder.MoveToBookmark("test", true, false);
// insert a paragraph
builder.Writeln();
            
doc.Save(@"C:\Temp\out.docx");