none
Handling outlook folder events RRS feed

  • Question

  • I want to handle the event when an outlook folder is deleted manually from an outlook root folder or a parent folder. Is there a way to handle such event ? Where do I register this event ?

    I tried the following.

     private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {  
               // Application.GetNamespace("MAPI").Folders.FolderRemove += new Microsoft.Office.Interop.Outlook.FoldersEvents_FolderRemoveEventHandler(Application_FolderRemove);
                //Application.GetNamespace("MAPI").Folders.FolderAdd += new Microsoft.Office.Interop.Outlook.FoldersEvents_FolderAddEventHandler(UsrAppln_FolderAdd);

            }


    But they don't seem to work when I manually delete a folder from the root folder.


    I have one more question. Is there a way to programatically protect the  PST file with a password ? I mean I want to get the password from the end user, and apply it on the PST file ? Is there any API on the PST store to do this ?

    Thanks
    Ram
    Friday, September 7, 2007 6:37 PM

All replies

  • Your event handlers are working with the Session object's Folders collection, not the Folders collection that begins at the root folder of a particular data store. In other words,for the first store in the mail profile, you'd use Application.GetNamespace("MAPI").Folders.Item(1).FolderRemove, not Application.GetNamespace("MAPI").Folders.FolderRemove.

     

    Outlook does not expose the PST password programmatically.

    Wednesday, September 19, 2007 1:17 PM
    Moderator
  • hi,

    this line of code does not fire event. would you please give some code to implement it & at which event to write the code.

     

    Thursday, June 10, 2010 9:53 AM
  • You need to declare a Folders object variable at the class level, set that object to the root folder, and subscribe to its events. Without the class-level declaration, the event-enabled object will go out of scope when ThisAddin_Startup finishes and will not fire events. 

    Sorry, but I some problems in the expression I gave for setting the Folders variable. One is that Application refers to the add-in, not an Outlook.Application object. Get the Outlook.Application object from Globals.ThisAddin.Application. Once you have that object variable (e.g. as outApp), you'd use outApp.GetNamespace("MAPI").Folders.Item(1).Folders to return the Folders collection for the root of the first information store. But that expression is just shorthand. In reality, as a best practice, you should return each object in a separate statement as a separate object variable, so that those variables can all be set to null when you're done with them, so that garbage collection can take care of them. Unfortunately, I can't code that for you, because I only do VB languages. 

    Wednesday, June 30, 2010 10:56 PM
    Moderator