Hi Ken,
Thanks for detailed reply,
I did the same, only thing I am missing is maintaining a Custom Class,
instead of that I have used Global List of Outlook.MAPIFolder.
And Recursion code is inside AddEventHandlers() Method.
But it's not working
Her is the code missing in my last post:
Global variable List<Outlook.MAPIFolder> folders;
void AddEventHandlers(Outlook.Folder folder)
{
folders.Add(folder);
logger.Debug("Adding ItemRemove eventhandler to " + folder.Name);
folder.Items.ItemRemove += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemRemoveEventHandler(Items_ItemRemove);
IEnumerator enumrator = folder. Folders.GetEnumerator();
while (enumrator.MoveNext())
{
Outlook.Folder tempFolder = (Outlook.Folder)enumrator.Current;
if (tempFolder != null)
{
AddEventHandlers(tempFolder);
}
}
}
<kenslovak@mvps.org> wrote in message
news:u4TfYs$KKHA.4004@TK2MSFTNGP05.phx.gbl...
> As you can see in the Object Browser there isn't an Explorer level event
> you can use.
> When I need to handle multiple folders, Explorers, Items collections,
> Inspectors, etc. I set up a class to handle what I need, including all
> events I want to handle. Then I maintain a set of those classes in a
> collection/list/whatever to keep them alive.
> For ItemRemove() and/or ItemAdd() I would do a recursive search of all
> folders loaded that I was interested in and grab the Items collection for
> each one, setting the Items collection object in my class to that Items
> collection and putting it in my list. Then the events would fire
> automatically. On shutdown I'd just unwind the list collection and null
> out everything.
> The code you show is non-recursive, it would only return top level folders
> of the NameSpace object, which would be at the Outlook Today level (top of
> store). If you have only one PST or mailbox loaded you'd get exactly 1
> handler installed and it would likely be useless. I'd recursively call
> each Session.Folders.Item() object and dig down into those also to get all
> the folders and their Items collections.
> >
>
> "Ashutosh Jogdande" <ashutosh_jogdande@persistent.co.in> wrote in message
> news:ujM97W%23KKHA.6016@TK2MSFTNGP05.phx.gbl...
> > Hi Ken,
>
>> Thanks for quick reply.
>
>> By adding ItemRemove event handler on outlookExplorer.CurrentFolder I am
> > able to catch the event.
>
>> But How to add event handler for all folders when addin gets loaded, as
> > we want to catch events for the mails which are getting archived or Moved
> > using Email-Rules.
>
>> I have tried by adding event handler to all the folders on addin startup,
> > but it didn't work.
>
>> Is there any way to trap this event at Explorer level?
>
>> Here is the code :
> > IEnumerator enumrator =
> > _outlookApplication.Session.Folders.GetEnumerator();
> > while (enumrator.MoveNext())
> > {
> > Outlook.Folder folder = (Outlook.Folder)enumrator.Current;
> > if (folder != null)
> > {
> > AddEventHandlers(folder);
> > }
> > }
>
>> where AddEventHandlers recursively adding event hadler to each folder.
>
>> Thanks,
> > Ashutosh
>