BookMark for the complete Table RRS feed

  • Question

  • Hi,

    I need to place a bookmark for the whole table in word template and content from "document.xml" file should be as shown below,

    <w:bookmarkStart w:name="table" w:id="1"/>

    <w:bookmarkEnd w:id="1"/>

    Please advise, how to achieve 

    Note : FYI, pragmatically using open xml API, i have applied bookmark for the whole table and got the xml content as expected .



    • Edited by MahaMN Friday, March 17, 2017 7:30 AM
    Friday, March 17, 2017 7:17 AM

All replies

  • Hello Maha,

    We could use InsertBefore<T>  method andInsertAfter<T>  method to insert bookmark.


                using (WordprocessingDocument doc =
             WordprocessingDocument.Open(filepath, true))
                    Body body = doc.MainDocumentPart.Document.Body; 
                    Table table = doc.MainDocumentPart.Document.Body.Elements<Table>().First();
                    BookmarkStart bookmarkStart = new BookmarkStart() { Name = "table", Id = "1" };
                    BookmarkEnd bookmarkEnd = new BookmarkEnd() { Id = "1" };
                    body.InsertBefore<BookmarkStart>(bookmarkStart, table);
                    body.InsertAfter<BookmarkEnd>(bookmarkEnd, table);



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, March 20, 2017 5:16 AM