Jim
Jim

Reputation: 2828

Pass Outlook addin via BHO to javascript

I am trying to pass the Outlook addin object via VSTO C# to the embeded html page in the Internet explorer. However, it seems that the object it not properly passed as the ActiveInspector is always null. Any ideas how to fix that. The code I am using is

 private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
dynamic window = d.parentWindow; 
var windowEx = (IExpando)window; 
PropertyInfo p = windowEx.AddProperty("bhoModule"); 
p.SetValue(windowEx, Globals.ThiAddin.Application, null);
} 

The javascript which receives the object is bellow

 $('#showInfo-button').click(function () {
        if (window.bhoModule != null) {
            window.alert("ow.bhoModule != null");

            var objOutlook = window.bhoModule.Application;
            if (objOutlook == null) {
                window.alert("objOutlook is null");
                return;
            }
            var inspector = objOutlook.ActiveInspector(); <-- NULL
            if (inspector == null) {
                window.alert("inspector is null");
                return;
            }

            var currItem = inspector.CurrentItem;
            if (currItem == null) {
                window.alert("currItem is null");
                return;
            }

            var sender = currItem.Sender;
            if (sender == null) {
                window.alert("sender is null");
                return;
            }


            $('#from').val(sender.Name);
            $('#email').val(sender.Address);
            $('#subject').val(currItem.Subject);
            $('#received').val(currItem.ReceivedTime);
        }
    });

Upvotes: 0

Views: 100

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66276

Use Application.ActiveExplorer.Selection.Item(1) in JavaScript.

Upvotes: 1

Related Questions