none
Event for Folder Add/Rename/Delete RRS feed

  • Question

  • I am developing an AddIn (C# .NET), which needs to know any changes in folders names inside Inbox.

    For example an event will be great which gets fired when user renames one of the folder in Inbox. There should be some way to know the existing folder name and what it is changing to. 

    Thanks

    Some background

    This Add In is trying to create backup of email items on local file system in the same structure as in Inbox folder structure. In case an user changes folder name in Outlook, corresponding file system directory must also be changed.

    I could apply FolderChange event handler on all the folders I am tracking and that triggers whenever there is change in folder name/ or items. But that doesn't tell me what caused the event (item was added/ deleted or folder renamed, and in case renamed which one). 


    • Edited by Mukesh BP Thursday, October 27, 2016 7:40 AM
    Thursday, October 27, 2016 6:42 AM

Answers

All replies

  • When Outlook starts have the add-in create a collection of the folder names for any folders in the Inbox.  Initially, this could be created from the Inbox Folders object. Keep the collection in sync with Outlook for any FolderAdd or FolderRemove events.

    When a FolderChange event is fired you can compare the folder names in the Inbox Folders object with the names in your collection. Any difference would be a renamed object.  A folder name in your collection that is not in the Inbox Folders object would be the old name.  The new name is passed as a parameter to the FolderChange event.
    • Edited by RLWA32 Friday, October 28, 2016 3:35 AM clarification
    Thursday, October 27, 2016 11:22 AM
  • Hi Mukesh BP,

    you need to code and check that if there is some change in the folders or not.

    to get list of all the folders you can use the code mentioned below.

    foreach (MAPIFolder folder in olNS.Folders)
    {
        GetFolders(folder);
    }
    
    public void GetFolders(MAPIFolder folder)
    {
        if (folder.Folders.Count == 0)
        {
             Console.WriteLine(folder.FullFolderPath);
        }
        else
        {
             foreach (MAPIFolder subFolder in folder.Folders)
             {
                  GetFolders(subFolder);
             }
        }
    }

    then you can try to compare it with your backup and find the results.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 28, 2016 3:17 AM
    Moderator
  • Assume I have following folders at start (to simplify things, all directly under inbox):

    ABC, PQR, XYZ

    In the next scan, you observed ABC, PTT, XYZ. You can't tell if PQR was renamed to PTT or PQR was deleted and PTT was created new.

    Friday, October 28, 2016 3:57 AM
  • You track additions and deletions separately with FolderAdd and FolderRemove
    Friday, October 28, 2016 4:20 AM
  • Hi Mukesh BP,

    I agree with the suggestion given by the RLWA32.

    you can try to use Folders.FolderAdd Event  and Folders.FolderRemove Event.

    following is the link for these 2 events please check it may solve your issue.

    Folders.FolderAdd Event (Outlook)

    Folders.FolderRemove Event (Outlook)

    Regards

    Deepak 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 31, 2016 2:11 AM
    Moderator
  • I marked this as answer but the whole process is utterly inefficient. 

    FolderChange event is fired not only when there are changes in the folder structure but also when any items are added, removed etc. Compared with those, actual folder changes are relatively rare. Yet you have to scan the folder structure (recursively, expensive operation) and compare against the old structure, each time FolderChange event is fired. Too much of an overhead.

    I am also thinking of an alternate design where I could disable Rename from context menu and provide my own custom Rename option (which will pop a box asking for new folder name). Although I am not sure how will I handle changes in folder not done through context menu.

    Tuesday, November 1, 2016 2:03 AM
  • Unfortunately the Outlook Object Model does not provide a FolderRename event. 

    You might consider using Extended MAPI to register for hierarchy table notifications as an alternative workaround.

    Tuesday, November 1, 2016 3:29 AM
  • Hi Mukesh ,

    I can understand the issue faced by you regarding recursive operation and there is nothing that can capture the rename operation of folder in outlook.

    but currently we have only this workaround available.

    if you think that this feature should be add in the future then please try to submit your feedback about this.

    Outlook User Voice 

    Thanks for your understanding.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 1, 2016 7:50 AM
    Moderator