Outlook 2016插件附件选择问题
问题描述:
我已经为选定的附件创建了一个Outlook插件来获取附件的详细信息。并在Outlook 2010中正常工作。 但是,当我为Outlook 2016构建它时,它将变为空。Outlook 2016插件附件选择问题
下面是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 。 请建议做什么?
此致 沙龙
答
相信观开发增加了额外的逻辑,用于释放作为参数传递对象(附件)。所以,你需要在事件处理程序中收集所有必需的信息,因为只要方法结束,对象就可以被销毁。事件处理人员被解雇后,没有人能保证物体是活的。你在AttachmentContextMenuDisplay
事件处理程序中获得有效的对象吗?
所有的Outlook加载项都应该在不再需要时系统地释放它们对Outlook对象的引用。完成使用后,请使用System.Runtime.InteropServices.Marshal.ReleaseComObject释放Outlook对象。然后在Visual Basic中将变量设置为Nothing(C#中的空值)以释放对该对象的引用。在Systematically Releasing Objects文章中阅读更多。
你有解决这个问题吗? – Pooran
你找出原因了吗?这解决了吗? – Stavm