c# - How can I remove bookmarks from an OpenXML docx file? -


i thought following work:

var bod = worddoc.maindocumentpart.document.body;  foreach (var bookmark in bod.descendants<bookmarkstart>()) {     bookmark.remove(); }  foreach (var bookmark in bod.descendants<bookmarkend>()) {     bookmark.remove(); } 

but corrupts file.

try this, worked on document.

var bs = worddoc.maindocumentpart.document              .descendants<bookmarkstart>()              .tolist();         foreach (var s in bs)             s.remove();  var = worddoc.maindocumentpart.document              .descendants<bookmarkend>()              .tolist();         foreach (var e in be)             e.remove(); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -