Trying to insert bookmark content
Hi
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);
bn.MoveToBookmark(bookMarkName);
//Create a temp word document
mStream = new MemoryStream(bookMarkText);
WordDocument tempDoc = new WordDocument();
tempDoc.Open(mStream,FormatType.Doc);
TextBodyPart BodyPart = new TextBodyPart(tempDoc);
bn.ReplaceBookmarkContent(BodyPart);
document.Save(Server.MapPath("~/dummy.doc"), FormatType.Doc);
}
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);
bn.MoveToBookmark(bookMarkName);
//Create a temp word document
mStream = new MemoryStream(bookMarkText);
WordDocument tempDoc = new WordDocument();
tempDoc.Open(mStream,FormatType.Doc);
TextBodyPart BodyPart = new TextBodyPart(tempDoc);
bn.ReplaceBookmarkContent(BodyPart);
document.Save(Server.MapPath("~/dummy.doc"), FormatType.Doc);
}
SIGN IN To post a reply.
3 Replies
BP
Bhuvaneswari P
Syncfusion Team
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:
Please download the sample from the below location:
http://files.syncfusion.com/samples/DocIO.windows/DocIO_Bookmark_81106.zip
Please try this and let us know if you face any issues in that.
Best Regards,
Bhuvana
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:
http://files.syncfusion.com/samples/DocIO.windows/DocIO_Bookmark_81106.zip
Please try this and let us know if you face any issues in that.
Best Regards,
Bhuvana
AD
Administrator
Syncfusion Team
May 18, 2009 10:58 AM UTC
Hi
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
Thanks
Ross
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
Thanks
Ross
BP
Bhuvaneswari P
Syncfusion Team
May 20, 2009 11:24 AM UTC
Hi,
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
part.BodyItems.Add(en2.Clone())
Next
Else
part.BodyItems.Add(en1.Clone())
End If
Next
End If
Next
Dim navi As New BookmarksNavigator(doc)
navi.MoveToBookmark("Essential_DocIO")
navi.InsertTextBodyPart(part)
Here is the sample which illustrates the above said feature:
http://files.syncfusion.com/samples/DocIO.windows/InsertBookmark_56058.zip
Please try this and let us know if this helps you.
Best Regards,
Bhuvana
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
part.BodyItems.Add(en2.Clone())
Next
Else
part.BodyItems.Add(en1.Clone())
End If
Next
End If
Next
Dim navi As New BookmarksNavigator(doc)
navi.MoveToBookmark("Essential_DocIO")
navi.InsertTextBodyPart(part)
Here is the sample which illustrates the above said feature:
http://files.syncfusion.com/samples/DocIO.windows/InsertBookmark_56058.zip
Please try this and let us know if this helps you.
Best Regards,
Bhuvana
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
AD Administrator
- May 12, 2009 03:57 PM UTC
- May 20, 2009 11:24 AM UTC