c# - Outlook 2016 插件 AttachmentSelection 问题

标签 c# outlook-addin outlook-2016

我已经为选定的附件创建了一个 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/

相关文章:

c# - HttpContext.Current.User.Identity.Name 如何知道存在哪些用户名?

c# - 在 Microsoft Azure WebJobs 中运行的控制台应用程序中,HttpContext.Current 不为 null

c# - 如何捕获电子邮件

c# - 附件未出现在 Outlook 2016 中

c# - 从隐藏代码打开新的 Outlook 电子邮件 - 按钮对齐问题

c# - mysql 创建唯一索引,索引名称中带有空格

C#:带有以 Child 类型作为参数的方法的继承类:调用了错误的方法

c# - 如何使用 StorageItem 保存 vsto 加载项特定数据

c# - 获取 Outlook 2010 规则说明

c++ - 使用 Outlook 2016 : MAPISendMail fails in an windows application and returning "MAPI_E_FAILURE" as error code