Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 35736

Outlook Code: BeforeItemMove event not being triggered for all the folders

$
0
0

We have recently had a case where the BeforeItemMove event wasn’t being triggered when switching between two calendar folders in Outlook 2007 or 2010.

 

To subscribe for the event we were using the Outlook.Explorer.CurrentFolder property to retrieve the currently selected folder and that same object was being used for subscribing for the events.

 

We have done a bit of debugging around this and we have noticed that even though the CurrentFolder property was returning the correct data of the currently selected folder, the returned COM object was always the same. Because of this behaviour, we were subscribing for events for the same folder over and over again.

 

As a workaround, instead of using the Outlook.Explorer.CurrentFolder to retrieve an Outlook.Folder item, you need to use the Namespace.GetFolderFromID method as follows:

 

   1: Outlook.Folder currentFolder;
   2: Outlook.Namespace _Namespace;
   3:  
   4: /// <summary>
   5: /// This event occures when another folder has been selected in this explorer.
   6: /// </summary>
   7: void _Explorer_FolderSwitch()
   8: {
   9:  
  10:     if (currentFolder != null)
  11:     {
  12:         currentFolder.BeforeItemMove -= new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(_Folder_BeforeItemMove);
  13:     }
  14:  
  15:     currentFolder = (Outlook.Folder)ThisAddIn._NameSpace.GetFolderFromID(_Explorer.CurrentFolder.EntryID);
  16:  
  17:     if (currentFolder == null)
  18:         return;
  19:  
  20:     currentFolder.BeforeItemMove += new Outlook.MAPIFolderEvents_12_BeforeItemMoveEventHandler(_Folder_BeforeItemMove);
  21:  
  22: }

Viewing all articles
Browse latest Browse all 35736

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>