wordpress hit counter
Re: remove Bookmark - WordprocessingML - Formats - OpenXML Developer

Re: remove Bookmark

Formats

Discussions about working with different Open XML Formats

remove Bookmark

  • rated by 0 users
  • This post has 1 Reply |
  • 1 Follower
  • Help Help Help

     

    I am desperatly seeking for a solution. I want to remove a bookmark with openxml SDK 2.0. Bookmark consists of a start node and an end node and a run with text in between.

    I able to locate the bookmark start with the following:

    var res = from bm in mainPart.Document.Body.Descendants<BookmarkStart>()

    where bm.Name == "STG_DAT"

    select bm;

    var bookmarkStart = res.SingleOrDefault();

     

    Please help I have no idea

  • Hi dknabben

    I believe you were on the correct track but just needed to find the BookmarkEnd too and remove both.

    Try giving this code a go as it works for me:

    var bookmarkStart = mainPart.Document.Body.Descendants().Where(bms => bms.Name == "testBookmark").SingleOrDefault();

    var bookmarkEnd = mainPart.Document.Body.Descendants().Where(bme => bme.Id.Value == bookmarkStart.Id.Value).SingleOrDefault();

    bookmarkStart.Remove();
    bookmarkEnd.Remove();
Page 1 of 1 (2 items)