views:

998

answers:

2

i have this "simple" Outlook-Object:

Outlook.Explorer olExplorer = this.Application.ActiveExplorer();

in "ThisAddin_StartUp" i register the olExplorer.FolderSwitch event to a function olExplorer_FolderSwitch(). There i must create an Outlook-Folder Object from the current Folder:

Outlook.Folder f = olExplorer.CurrentFolder as Outlook.Folder;

But: the property "CurrentFolder" is of type MAPIFolder and cant be used as Outlook.Folder. How can i "cast" the CurrentFolder-Property to an Outlook.Folder? - without loosing the event-handler? If i do this simple conversion, the object f will not fire the event BeforeItemMove - because f is NULL where olExplorer.CurrentFolder is not

A: 

I don't really get the issue, as according to the documentation Explorer.CurrentFolder returns an object of type Outlook.Folder, not MAPIFolder. I personally haven't done any VSTO (nor 2007 specific) development, but are you sure you aren't mixing up different versions of the object model?

Anyway, Outlook.Folder and MAPIFolder share the EntryID and StoreID property. You can use those to lookup the corresponding Outlook.Folder using NameSpace.GetFolderFromID. The namespace in question is acquired through Application.GetNamespace("MAPI").

Paul-Jan
+1  A: 

I have not found an easy way. You could find the Outlook.Folder from the folders sessions.

If you compare the EntryID you will get the right folder.

Outlook.Folders olFolders = OutlookApp.Session.Folders;

for (int i = 1; i <= olFolders.Count; i++)
{
   if (olFolders[i].EntryID == olExplorer.CurrentFolder.EntryID)
   {
      // folder found assign and use it.
   }
}

notice the start at 1 and count equal or less to get all your folders.

Khan