Can any tell me how to real all bookmarks in a word 2010 document using openXml 2.0. I was using Microsoft.Office.Interop.Word to read bookmarks but i am not able to deploy my website as it was having issues so i switched to openxml can anyone tell me how to read all bookmarks
Asked
Active
Viewed 2,484 times
1
-
I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Jan 05 '14 at 02:38
2 Answers
1
you can iterate through all
file.MainDocumentPart.RootElement.Descendants<BookmarkStart>()
like:
IDictionary<String, BookmarkStart> bookmarkMap =
new Dictionary<String, BookmarkStart>();
// get all
foreach (BookmarkStart bookmarkStart in file.MainDocumentPart.RootElement.Descendants<BookmarkStart>())
{
bookmarkMap[bookmarkStart.Name] = bookmarkStart;
}
// get their text
foreach (BookmarkStart bookmarkStart in bookmarkMap.Values)
{
Run bookmarkText = bookmarkStart.NextSibling<Run>();
if (bookmarkText != null)
{
string bookmarkText = bookmarkText.GetFirstChild<Text>().Text;
}
}
code extracted from https://stackoverflow.com/a/3318381/28004

Community
- 1
- 1

balexandre
- 73,608
- 45
- 233
- 342
-
By using this solution we cant find bookmarks present in Header and footer. – MaheshMajeti Jan 07 '14 at 13:18
0
Try this.I have used same in my project
http://www.legalcube.de/post/Word-openxml-sdk-bookmark-handling.aspx

MaheshMajeti
- 187
- 12