我已经为选定的附件创建了一个 Outlook 插件以获取附件的详细信息。并且它在 Outlook 2010 中运行良好。 但是当我为 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总是空的。 请建议该怎么做?
亲切的问候, 爱丽儿
最佳答案
我相信 Outlook 开发人员添加了一个额外的逻辑来释放作为参数对象(附件)传递的。因此,您需要在事件处理程序中收集所有必需的信息,因为一旦方法结束,对象就会被销毁。没有人能保证对象在事件处理程序被触发后仍然存在。您是否在 AttachmentContextMenuDisplay
事件处理程序中获得有效对象?
所有 Outlook 加载项都应在不再需要时系统地释放对 Outlook 对象的引用。使用 System.Runtime.InteropServices.Marshal.ReleaseComObject使用完毕后释放 Outlook 对象。然后在 Visual Basic 中将变量设置为 Nothing(在 C# 中为 null)以释放对该对象的引用。在 Systematically Releasing Objects 中阅读更多相关信息文章。
关于c# - Outlook 2016 插件 AttachmentSelection 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34917796/