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. Image for the cookie policy date
close icon

Creating new doc with GetBookmarkContent() from another doc

Hi, I would like to navigate to a book mark in DOC1 and select the contect between the start and end of that bookmark and copy that content to another new doc. How can I do this? please post any code samples.


4 Replies

AD Administrator Syncfusion Team April 8, 2008 12:27 PM UTC

Hi Yogesh,

Thank you for your interest in Syncfusion products.

DocIO has the support for navigating through the bookmarks in a document. You can use the below code for Creating new doc with GetBookmarkContent() from another doc:


[C#]
bodyPart = bk.GetBookmarkContent();
IWParagraph p= document1.AddSection().AddParagraph() ;
p.AppendText("this is the second document");
//Paste the first document bookmark content into another document[document1]
bodyPart.PasteAfter(p.Items[0]);
document1.Save("sample2.doc");


Here is the sample for your reference:
http://websamples.syncfusion.com/samples/DocIO.Web/6.1.0.34/72800/main.htm

Please try this and let me know if this helps.

Regards,
G.Yavana




YR Yogesh Ramakrishnan May 13, 2008 01:03 AM UTC

Hi, here is my code, let me know why this code does not work as I expect it to.

'Get the template path
Dim ExamplePath As String = My.Settings.ExamplePath.ToString()
Dim TemplatePath As String = My.Settings.TemplatePath.ToString()

' Create a new document
doc = New WordDocument(TemplatePath & "Examples.dot")


If dsExample.Tables.Count > 0 AndAlso dsExample.Tables(0).Rows.Count > 0 Then

'get the filename.
Dim exampleFilename As String = dsExample.Tables(0).Rows(0)("Example_FileName").ToString() & ".doc"

'Open the file
Dim exampledoc As WordDocument = New WordDocument(System.IO.Path.Combine(ExamplePath, exampleFilename))


'The bookmark in the example
Dim bookmarkname As String = dsExample.Tables(0).Rows(0)("Example_BM_S").ToString()

'Get the book mark navigator
Dim bk As BookmarksNavigator = New BookmarksNavigator(exampledoc)

'get the Book mark for given Name
bk.MoveToBookmark(bookmarkname)

Dim bp As TextBodyPart = bk.GetBookmarkContent()

bp = bk.GetBookmarkContent()

Dim p As IWParagraph = doc.AddSection().AddParagraph()
p.AppendText("this is the Example document")

bp.PasteAfter(p.Items(0))



End If
return doc




BP Bhuvaneswari P Syncfusion Team May 27, 2008 08:55 AM UTC

Hi Yogesh,

Thanks for the code snippet.

We have tested using the same code but we are not able to reproduce the issue. We have tested this issue in the below environment:

Windows XP with Service pack2, office 2003 with sp3, VisualStudio 2005, .Net Framework 2.0 and Essential Studio version 6.2.0.40.
Sample:

http://websamples.syncfusion.com/samples/DocIO.Web/6.1.0.34/72800/main.htm


Could you please send us the modified sample with the below details.

1. System configuration
2. Office version
3. Essential studio version.

This would be help us to invetigate more on this issue and provide you an solution.

Best Regards,
Bhuvana



PG Paul Griffiths-DUPLICATE ACCOUNT- USE DT# 147667 June 11, 2014 11:42 AM UTC

Hi,

I've been trying to do something very similar, selecting the entire content of the main sections of my document and inserting these as bookmarks.
What I have found is the the bookmark navigator GetBookmarkContent() method falls over when the bookmark content spans over a section break.

Can you confirm that this is a limitation I have with bookmarks? Or is there a way I can still use bookmarks that span over a section break?

Cheers

Paul

Loader.
Live Chat Icon For mobile
Up arrow icon