Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Thu Oct 06, 2011 6:40 am


I have a problem in reading text from word document (.doc/.docx) bookmarks. Please help to provide some sample code in C# to read the text from Bookmarks in document.

I can go through the bookmarks as follows: The code is:-

Document document = new Document();

//This can read the whole text from a .doc file; However I need to specifically extract text from bookmarks.
this.rtbText.Text = document.GetText();

foreach (Bookmark selection in document.Bookmarks)
///Need to add the code here to read the text from corresponding bookmark- from start to end.

Please help.

Thank you,
Last edited by valaranip on Fri Oct 07, 2011 1:03 am, edited 1 time in total.

Posts: 2
Joined: Tue Oct 04, 2011 2:11 am

Sun Oct 09, 2011 7:55 am

hello Prashant,

Sorry for any inconveniences caused by us and thank you for your patience with our reply.

If you want to get the text between markbookstart and bookmarkend, you can try the code as below:
Code: Select all
            Document doc = new Document();
            foreach (Bookmark bookmark in doc.Bookmarks)
                BookmarkStart bookmarkStart = bookmark.BookmarkStart;
                IDocumentObject nextNode = bookmarkStart.NextSibling;
                StringBuilder buffer = new StringBuilder();
                while (nextNode is ParagraphBase && nextNode != bookmark.BookmarkEnd)
                    if (nextNode is TextRange)
                        buffer.Append((nextNode as TextRange).Text);
                    nextNode = nextNode.NextSibling;             

If you still have any question, please don’t hesitate to contact us for any thing at any time.
Technical Support/Developer,
e-iceblue Support Team
User avatar

Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Thu Oct 13, 2011 8:00 am

Hi Tina,

Thanks a lot for your reply. It is ok now.


Posts: 2
Joined: Tue Oct 04, 2011 2:11 am

Return to Spire.Doc