Read bookmarks in outlook MSG file with C# -
my goal somehow able read bookmarks in outlook .msg file, replace them different text. want c#.
i know how access body , change text, wondering if there way access directly list of bookmarks , location can replace them, instead going through whole body text, splitting up, etc etc...
edit: this how bookmark window looks like window 1 can assign bookmarks, should possible obtain list via c#.
any relevant info appreciated. in advance.
since outlook most uses word it's body editor - need add project reference microsoft.office.interop.word.dll , access outlook inspector's wordeditor
during inspector.activate
event. once have access word.document
- it's trivial load bookmarks
, access/modify values.
outlook.inspector inspector = globals.thisaddin.application.activeinspector(); ((outlook.inspectorevents_10_event)inspector).activate += () => { // validation ensure using word editor if (inspector.editortype == outlook.oleditortype.oleditorword && inspector.iswordmail()) { word.document worddoc = inspector.wordeditor word.document; if (worddoc != null) { var bookmarks = worddoc.bookmarks; foreach (word.bookmark item in bookmarks) { string name = item.name; // bookmark name word.range bookmarkrange = item.range; // bookmark range string bookmarktext = bookmarkrange.text; // bookmark text item.select(); // triggers bookmark selection } } } };
Comments
Post a Comment