我已经为所选附件创建了Outlook外接程序,以获取附件的详细信息。它在Outlook2010中运行良好。但当我为outlook 2016构建它时,它就变成了null。
以下是ThisAddIn.cs中的代码:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
System.Reflection.Assembly assemblyInfo = System.Reflection.Assembly.GetExecutingAssembly();
Uri uriCodeBase = new Uri(assemblyInfo.CodeBase);
string Location = Path.GetDirectoryName(uriCodeBase.LocalPath.ToString());
var path = Location.Split(new string[] { "bin" }, StringSplitOptions.RemoveEmptyEntries);
var rootDir = path[0].ToString();
var forPermissionsRootDirectory = Path.GetDirectoryName(rootDir);
SetPermissions(forPermissionsRootDirectory);
app = this.Application;
app.AttachmentContextMenuDisplay += new Outlook.ApplicationEvents_11_AttachmentContextMenuDisplayEventHandler(app_AttachmentContextMenuDisplay);//attach Attachment context Menu Event//
}
void app_AttachmentContextMenuDisplay(Office.CommandBar CommandBar, Outlook.AttachmentSelection selection)
{
selectedAttachment = selection;
RibbonUI.InvalidateControlMso("ContextMenuAttachments");//will get XML file data//
}
这是AttachmentContextMenu.cs中的代码:
public void OnOpenMyMotionCalendarButtonClick(Office.IRibbonControl control)
{
Outlook.AttachmentSelection selection = ThisAddIn.selectedAttachment;
if ((selection.Count > 0))
{
//My further working
}
}
在所选内容中,outlook 2016始终为空。请建议一下该怎么做?
亲切的问候,艾瑞尔
发布于 2016-01-24 23:32:41
我相信Outlook开发人员添加了额外的逻辑来释放作为参数对象(附件)传递的对象。因此,您需要在事件处理程序中收集所有必需的信息,因为一旦方法结束,对象就会被销毁。没有人能保证在事件处理程序被触发后对象是活动的。在AttachmentContextMenuDisplay
事件处理程序中是否获得有效的对象?
当不再需要Outlook对象时,所有Outlook外接程序都应系统地释放它们对Outlook对象的引用。使用完Outlook对象后,使用System.Runtime.InteropServices.Marshal.ReleaseComObject释放该对象。然后在Visual Basic中将变量设置为Nothing (在C#中为null)以释放对该对象的引用。在Systematically Releasing Objects文章中阅读更多关于这方面的内容。
https://stackoverflow.com/questions/34917796
复制相似问题