【问题标题】:Items_ItemAdd listener for folder and it's sub folders in OutlookItems_ItemAdd 文件夹监听器及其在 Outlook 中的子文件夹
【发布时间】:2013-07-29 07:14:21
【问题描述】:

我正在为 Outlook 开发一些 COM 插件扩展,我想在将项目放入特定文件夹或其子文件夹时触发事件。我正在使用 Items_ItemAdd 方法作为 drop 事件侦听器。 如果将项目放入“父”文件夹,它可以正常工作,但将项目放入子文件夹时没有任何反应。

这是我正在使用的代码:

private void ThisAddIn_Startup(object sender, System.EventArgs e
{
    foreach (Outlook.Folder folder in foldersPaths)
    {
       costumUserFolder = folder.Items;
       costumUserFolder.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
    }
}

foldersPaths 是 Outlook.Folder 的列表,包含我想监听事件的文件夹及其所有子文件夹。

我正在Items_ItemAdd 方法中监听此事件。

有什么想法吗?

【问题讨论】:

    标签: c# drag-and-drop outlook-addin comaddin


    【解决方案1】:

    您需要在每个文件夹的 Items 集合上安装事件接收器。

    为确保在您的应用运行时所有 Items 对象都处于活动状态,请将 Items 存储在列表中(例如 List<Outlook.Items>

    【讨论】:

      【解决方案2】:
          //Please find the implemented tested working Solution:
      
      
          Outlook.Items oMailItems = null; //Globally declared object
          List<Outlook.Items> allInboxFolder = new List<Outlook.Items>(); //Globally declared
      Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
          //Implemented Threading for each item recieved to Inbox Folder
          //Outlook.Items oMailItems = null; //Globally declared object
          oMailItems = inbox.Items;
          oMailItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(ThreadStarter);
          allInboxFolder.Add(oMailItems); //make all subfolders events live
          foreach (Outlook.Folder folder in inbox.Folders)
          {
              oMailItems = folder.Items;
              oMailItems.ItemAdd += new   Outlook.ItemsEvents_ItemAddEventHandler(ThreadStarter);
              allInboxFolder.Add(oMailItems);
          }
      
          private void ThreadStarter(Object Item)
          {
              //InboxFolderItemAdded invoked by thread
              System.Threading.Thread IncomingMailThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(this.InboxFolderItemAdded));
              IncomingMailThread.IsBackground = true;
              IncomingMailThread.Start(Item);
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-16
        • 2019-01-02
        • 2016-07-24
        • 1970-01-01
        • 1970-01-01
        • 2014-05-08
        相关资源
        最近更新 更多