We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Trying to insert bookmark content

Thread ID:





81106 May 12,2009 03:57 PM UTC May 20,2009 11:24 AM UTC WinForms 3
Tags: DocIO
Administrator [Syncfusion]
Asked On May 12, 2009 03:57 PM UTC


I am trying to insert bookmark contents with an byte[] array using TextBodyPart, but the results are not showing, my code is as below:

private void CreateBookMark(WordDocument document, string bookMarkName, byte[] bookMarkText)

//Insert bookmark contents
BookmarksNavigator bn = new BookmarksNavigator(document);

//Create a temp word document
mStream = new MemoryStream(bookMarkText);

WordDocument tempDoc = new WordDocument();

TextBodyPart BodyPart = new TextBodyPart(tempDoc);

document.Save(Server.MapPath("~/dummy.doc"), FormatType.Doc);


Bhuvaneswari P [Syncfusion]
Replied On May 14, 2009 09:00 AM UTC

Hi Ross,

Thank you for your interest in Syncfusion products.

In your code snippet I have noticed that you have not added items in the TextBodyPart, you have just created TextBodypart with empty item. So it’s not displaying anything in the Bookmark content. Please add the items in the TextBodyPart before replacing the bookmark. Please refers to the below code snippet to do so:

//Create a temp word document
MemoryStream mStream = new MemoryStream(bookMarkText);

WordDocument tempDoc = new WordDocument();
tempDoc.Open(mStream, FormatType.Doc);

TextBodyPart bodyPart = new TextBodyPart(tempDoc);
//Add items into the TextBodyPart
bodyPart.BodyItems.Add(tempDoc.Sections[0].Paragraphs[0] as WParagraph);

Please download the sample from the below location:

Please try this and let us know if you face any issues in that.

Best Regards,

Administrator [Syncfusion]
Replied On May 18, 2009 10:58 AM UTC


Basically I am trying to insert everything from the temp created doc (from stream) to the bookmark, in this case I have some Tables & text in the temp word doc, but inserting the paragraph[0] doesnt insert them all, basically I want the whole contents of the temp word doc from stream to be inserted into the bookmark as it is


Bhuvaneswari P [Syncfusion]
Replied On May 20, 2009 11:24 AM UTC


Thanks for the update.

Yes, it is possible to "Import contents of a second document into a particular bookmark location of the first document". By using adding the document content into the TextBodyPart and insert this TextBodyPart content into the Bookmark content. Please refers the below code snippet to do so:

Dim doc As New Syncfusion.DocIO.DLS.WordDocument(Server.MapPath("Bookmark_Template.doc"))
Dim doc1 As New WordDocument(Server.MapPath("doctortf.doc"))
Dim part As New TextBodyPart(doc1)
For Each en As Entity In doc1.ChildEntities
If TypeOf en Is WSection Then
Dim sec As WSection = TryCast(en, WSection)
For Each en1 As Entity In sec.ChildEntities
If TypeOf en1 Is WTextBody Then
Dim body As WTextBody = TryCast(en1, WTextBody)
For Each en2 As Entity In body.ChildEntities
End If
End If
Dim navi As New BookmarksNavigator(doc)

Here is the sample which illustrates the above said feature:

Please try this and let us know if this helps you.

Best Regards,


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon