我正在尝试通过VSTO C#将Outlook插件对象传递到Internet Explorer中的嵌入式html页面。但是,它似乎未作为ActiveInspector正确传递的对象始终为null。任何想法如何解决这个问题。我正在使用的代码是
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);
}
接收对象的javascript是下面的
$('#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);
}
});
答案 0 :(得分:1)
在JavaScript中使用Application.ActiveExplorer.Selection.Item(1)
。