Access an editable document in an Outlook reading pane

I wrote a simple VSTO addon that inserts a hyperlink into an email message when a user clicks the feed button. Here is a sample code:

private void button1_Click(object sender, RibbonControlEventArgs e) { var context = e.Control.Context as Inspector; if (context != null) { if (context.IsWordMail()) { var doc = context.WordEditor as Document; if (doc != null) { var sel = doc.Windows[1].Selection; doc.Hyperlinks.Add(sel.Range, "http://www.google.com", "", "", "Google", ""); } } } else if (e.Control.Context is Explorer) { Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer(); if (explorer.Selection.Count == 1) { Microsoft.Office.Interop.Outlook.Selection itemSelection = explorer.Selection; var item = itemSelection[1] as MailItem; // get the instance of WordEditor in a reading pane? } } } 

This works well when the email is edited in separate windows ( e.Control.Context is Inspector ).

If the messsage message is answered / forwarded and the reading pane is turned on, the editor is displayed inside the reading line ( e.Control.Context is Explorer ).

I cannot figure out how to get the Document instance in this case. I can access the item selected in Explorer, but I cannot figure out how to access the document editor displayed in the reading pane.

If I β€œpulled” the editor into a separate window, it works fine (context changes in Inspector).

Is there a way to access an email document that is being edited directly inside the reading area?


With a lot of help from Dmitry , who pointed me in the right direction, I found that in the Explorer class there is a property: Explorer.ActiveInlineResponseWordEditor , which gives you the editor displayed in a row.

+4
source share
1 answer
  • You can call MailItem.GetInspector, then Inspector.WordEditor. This should work fine in newer versions of Outlook.

  • You can use the SafeExplorer object in Redemption - it should work in all versions of Outlook, and it provides the SafeExplorer.ReadingPane ( ReadingPane ) property.

0
source

Source: https://habr.com/ru/post/1484022/


All Articles