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

Free Support Forum - aspose.com

Inserting Bookmark Programmatically

I have a document template (Postcard.doc).
The document has got a table and two rows.
I want to insert a bookmark at the top of the table and not inside.
If I use : builder.StartBookmark(“TestBookmark”);, then it is inserting in to the first cell of the table.

What I really want is there in the attached document : Postcard_BM.doc
I did that manually by cutting the table, inserting the bookmark at the top and pasting the table back.

Can I achieve similar functionality with Aspose.Word.



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. In the document created in MS Word there is a paragraphs before table and bookmarks is inserted into this paragraph. You can achieve the same using Aspose.Words. See the following code:

Document doc = new Document(@"Test001\PostCard.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

// Check whether the first node in the docuemnt is not Paragraph,

// If so add paragraph before this table.

if(doc.FirstSection.Body.FirstChild.NodeType != NodeType.Paragraph)


Paragraph par = new Paragraph(doc);

doc.FirstSection.Body.InsertBefore(par, doc.FirstSection.Body.FirstChild);

// Move DocumentBuilder cursor to the newly created paragraph.


// Insert Bookmark.

string bkName = "MyBookmark";




// Save output document.


Hope this helps.

Best regards.

Thanks Alexey.
Works great.