Folder Delete Event

N

Neetu

In outlook we are creating custom folder.
we need to catch folder delete event if user delete this folder or some
other code deletes it. Reason, all subfolders's properties of main folder
need to reset like some are attached with some url and some have event
handlers.

I am attaching BeforeFolderMove with main folder at the time of creation
private void CreateMainFolder()
{

MFMainfolder = mobjmfParent.Folders.Add("mainfoldername",
OlDefaultFolders.olFolderInbox);
Folder Folder = mobjmfTubetrak as Folder;
Folder.BeforeFolderMove += new
APIFolderEvents_12_BeforeFolderMoveEventHandler(mainFolder_BeforeFolderMove);

}

void mainFolder_BeforeFolderMove(MAPIFolder MoveTo, ref bool Cancel)
{

/// code to reset all subfolder properties....
}



when i am running this code for reset, some times BeforeFolderMove got fires
and some times not..

when i put breakpoint at BeforeFolderMove event is works every time.. but if
i run solution with out breakpoints, it fires randomly.

I am using c#, outlook 2005 and VSTO.

Any suggestion, or tips are welome.
 
K

Ken Slovak - [MVP - Outlook]

Your handle to the event is being lost due to the object going out of scope
and being garbage collected most likely. Declare your folder object for that
event at a class level so it won't go out of scope and get garbage
collected.
 
N

Neetu

All objects which is in use are at class level.

code work fine.. at debug mode with breakpoints at
mainFolder_BeforeFolderMove function.
but it does't get fires when i removes all break points.
 
K

Ken Slovak - [MVP - Outlook]

That's not true.

Your Folder object that has the event handler is being declared in the
CreateMainFolder() procedure. Look at your own code. Declare that object at
class level.
 
N

Neetu

Thanks Ken

Ken Slovak - said:
That's not true.

Your Folder object that has the event handler is being declared in the
CreateMainFolder() procedure. Look at your own code. Declare that object at
class level.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top