【问题标题】:Outlook 2016 plugin AttachmentSelection IssueOutlook 2016 插件附件选择问题
【发布时间】:2016-04-27 08:19:27
【问题描述】:

我为选定的附件创建了一个 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 始终为空。 请建议怎么做?

亲切的问候, 爱丽儿

【问题讨论】:

  • 你解决了这个问题吗?
  • 找到原因了吗?解决了吗?

标签: c# outlook-addin outlook-2016


【解决方案1】:

我相信 Outlook 开发人员添加了一个额外的逻辑来释放作为参数对象(附件)传递的内容。因此,您需要在事件处理程序中收集所有必需的信息,因为一旦方法结束,对象就会被销毁。没有人能保证在事件处理程序被触发后对象是活动的。你在AttachmentContextMenuDisplay 事件处理程序中得到了一个有效的对象吗?

所有 Outlook 加载项都应在不再需要时系统地释放其对 Outlook 对象的引用。使用完后,使用System.Runtime.InteropServices.Marshal.ReleaseComObject 释放 Outlook 对象。然后在 Visual Basic 中将变量设置为 Nothing(在 C# 中为 null)以释放对对象的引用。在Systematically Releasing Objects 文章中阅读更多相关信息。

【讨论】:

  • 实际上我面临的问题是当我右键单击电子邮件中的附件时,我添加了事件处理程序“app.AttachmentContextMenuDisplay += new Outlook.ApplicationEvents_11_AttachmentContextMenuDisplayEventHandler(app_AttachmentContextMenuDisplay);”不适用于 Outlook 2016,但适用于 Outlook 2010
  • 您的答案可能是正确的,但对回答 OP 帮助不大。
猜你喜欢
  • 1970-01-01
  • 2010-12-10
  • 1970-01-01
  • 2016-06-08
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多