none
Outlook Add in VSTO - MAPI folders events Folder add, folder move and folder change not hooked RRS feed

  • Question

  • MAPI folders events Folder add, folder move and folder change were not hooked with handlers after some create and delete folder custom actions.

    We are maintaining folder-message hierarchy for different users in mongo db. A separate server which will manipulate create, copy, move, delete and Restore to Outlook inbox folder actions on per user email box. We designed an outlook addin which will contact this server and form folder-message hierarchy on left side pane of MS office outlook. We are manipulating this folders hierarchy in outlook using Microsoft.office.interop.outlook dll (MAPIFolder class). We are registering event handlers for MAPI Folder folderadd, foldermove and folderchange events. Everything works well. But after certain folder creation action and delete action, all of a sudden handlers we registered with this events not binding and every subsequent folder create & delete actions collapsed not debugging. 

    Are we missing anything? could please reply Why event handlers registered are not called up for the respective events?

    Thanks in advance,

    Rajesh


    Monday, May 30, 2016 11:25 AM

Answers

  • Hello Edward,

    Solution: Whenever user select particular folder, if it's not of folder type that we named then we created it again and update it with the Server where we are maintaining that folder-message hierarchy.

    That's the solution we are using it right now.

    i have another one question to ask right now. How can i block edit folder name option? when a user click two times means it allow user to edit folder name. so could you please tell me any option to block user to edit folder name option like outlook block inbox folder name.

    Thanks in advance,

    Rajesh

    Wednesday, June 8, 2016 1:52 PM

All replies

  • Hi,

    According to the description, I've moved this thread to the Outlook for Developers forum.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Melon Chen
    TechNet Community Support


    Please mark the reply as an answer if you find it is helpful.

    If you have feedback for TechNet Support, contact tnmff@microsoft.com.
    Tuesday, May 31, 2016 6:36 AM
  • Please show the relevant snippets of your code that set up the event handlers and process the events.

    What is your version of Outlook?

    Can you reproduce the problem in OutlookSpy (click Folder button, go to the Events tab, looks at the log at the bottom of the window)?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, May 31, 2016 6:41 AM
  • One specific "gotcha" related to subscribing to events that Dmitry outlines on his website is that the objects you are subscribing to need to be defined in a global scope. I'm not sure if this practice applies to you, but I'm throwing it out there for you to try.

    Pseudo code:

    //Bad

    class MyClass {

    function SetupEventHandlers() {

      var folder = _session.getSelectedFolder()  
      folder.OnFolderAdd += someFunction;

    }

    }

    //Good

    class MyClass {

             Folder folder;

    function SetupEventHandlers() {

    folder = _session.getSelectedFolder()  
    folder.OnFolderAdd += someFunction;

    }

    }



    Tuesday, May 31, 2016 6:38 PM
  • Hello Rajesh,

    It is not clear what code you use for subscribing to the events. If you want to get a valuable answer you need to publish a piece of code which shows the issue you faced with.


    [custom.development]

    Wednesday, June 1, 2016 10:09 AM
  • Hi Rajesh,

    Did the suggestion from Nicholas work for you? If not, it would be helpful if you could share us your code which register these events. What do you mean with certain folder creation action?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, June 2, 2016 5:36 AM
  • Hello Eugene,

    one of our team member resolved that issue. thanks for the reply.

    i have another one question to ask right now. How can i block edit folder name option? when a user click two times means it allow user to edit folder name. so could you please tell me any option to block user to edit folder name option like outlook block inbox folder name.

    Thanks in advance,

    Rajesh

    Monday, June 6, 2016 7:04 AM
  • As you said, we are subscribing events for global declared folder only. 

    Thanks for reply,

    Rajesh

    Monday, June 6, 2016 7:12 AM
  • public class OutlookFolder
        {
            #region Properties

            public Outlook.Folder OLFolder { get; set; }

            /// <summary>
            /// Unique entryId
            /// </summary>
            public string EntryID { get; set; }

            #endregion

            #region Constructor

            public OutlookFolder(Outlook.Folder outlookFolder)
            {
                OLFolder = outlookFolder;
                EntryID = outlookFolder.EntryID;
                RegisterEvents();
            }

            public OutlookFolder(Outlook.Folder outlookFolder, PFFolder pfFolder)
            {
                OLFolder = outlookFolder;
                EntryID = outlookFolder.EntryID;
                RegisterEvents();
            }

            #endregion

            #region Events

            void Folders_FolderChange(Outlook.MAPIFolder folder)
            {
                    Outlook.Folder changedFolder = folder as Outlook.Folder;
                    //respective actions
            }

            void Folder_BeforeFolderMove(Outlook.MAPIFolder moveToFolder, ref bool isOperationCanceled)
            {
                    Outlook.Folder targetFolder = moveToFolder as Outlook.Folder;
                    //respective actions
            }

            void Folders_FolderAdd(Outlook.MAPIFolder folder)
            {
                    Outlook.Folder newFolder = folder as Outlook.Folder;
                    //respective actions
            }

            void Folder_BeforeItemMove(object Item, Outlook.MAPIFolder MoveTo, ref bool Cancel)
            {
                    Outlook.Folder targetFolder = MoveTo as Outlook.Folder;
            }

            void Items_ItemAdd(object Item)
            {
                    Outlook.Folder folder = this.OLFolder;
                    //respective actions
            }

            #endregion

            #region Methods

            private void RegisterEvents()
            {
                    this.OLFolder.BeforeFolderMove += Folder_BeforeFolderMove;
                    this.OLFolder.Folders.FolderAdd += Folders_FolderAdd;
                    if (this.IsPFFolder || this.OLFolder.Name == Utility.RootOutlookFolderName)
                        this.OLFolder.Folders.FolderChange += Folders_FolderChange;

                    this.OLFolder.BeforeItemMove += Folder_BeforeItemMove;
                    this.OLFolder.Items.ItemAdd += Items_ItemAdd;
            }

            private void UnRegisterEvents()
            {
                    this.OLFolder.BeforeFolderMove -= Folder_BeforeFolderMove;
                    this.OLFolder.Folders.FolderAdd -= Folders_FolderAdd;
                    if (this.IsPFFolder || this.OLFolder.Name == Utility.RootOutlookFolderName)
                        this.OLFolder.Folders.FolderChange -= Folders_FolderChange;

                    this.OLFolder.BeforeItemMove -= Folder_BeforeItemMove;
                    this.OLFolder.Items.ItemAdd -= Items_ItemAdd;
            }

            public void Cleanup()
            {
                if (OLFolder != null)
                {
                    try
                    {
                        this.UnRegisterEvents();
                    }
                    catch { }
                }
            }

         
    Monday, June 6, 2016 10:35 AM
  • Hi Rajesh,

    >>one of our team member resolved that issue

    It would be appreciated if you could share us your solution, and then mark the reply as answer, then others who run into the same issue would find the solution easily.

    For new issue, I would suggest you post a new thread, and then community members could focus on this new issue.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, June 7, 2016 8:01 AM
  • Hello Edward,

    Solution: Whenever user select particular folder, if it's not of folder type that we named then we created it again and update it with the Server where we are maintaining that folder-message hierarchy.

    That's the solution we are using it right now.

    i have another one question to ask right now. How can i block edit folder name option? when a user click two times means it allow user to edit folder name. so could you please tell me any option to block user to edit folder name option like outlook block inbox folder name.

    Thanks in advance,

    Rajesh

    Wednesday, June 8, 2016 1:52 PM