locked
Outlook 2010 Context Menu RRS feed

  • Question

  • In Outlook 2007 I could hide default context menu items when you right click on certain folders or items, but it doesn't seem to work in Outlook 2010. Is there a different way of doing it?
    I found this article http://msdn.microsoft.com/en-us/library/ee692172%28office.14%29.aspx#OfficeOLExtendingUI_FolderContextMenu where it describes how to add context menu items, but it doesn't say anything about how to hide context menu items in Outlook 2010.


    Victor - Software Developer
    TeamLook - TFS Outlook Addin , TeamSpec - TFS Word Addin
    Thursday, February 25, 2010 6:58 PM

Answers

  • Your code not behaving nicely in Outlook 2010 is expected.  In Outlook 2007, you could handle the FolderContextMenuDisplay event, then iterate through the Controls collection until you find the ID of the control you want to disable. Then you could simply set the Visible and Enabled properties to false as follows:

    void
    app_FolderContextMenuDisplay(Office.CommandBar CommandBar, Outlook.MAPIFolder Folder)
    {
        foreach (Office.CommandBarControl menuItem in CommandBar.Controls)
        {
            if (menuItem.Id == 7888)
            {
                menuItem.Enabled =
    false;
                menuItem.Visible = false;
            }
        }
    }

    However, This event as well as the Commandbar object model in general has been deprecated for Outlook 2010. This means that you can still use the object model, but Microsoft makes no guarantees as to how well it will work. This article lists deprecated objects and members - Outlook 2010 Object Model Changes Since Earlier Versions.

    As you have probably concluded by reading the article you mention above, the best practice guidance for Outlook 2010 is to use Ribbon XML to customize context menus in Outlook. That article does not explicitely point out how to enable and disable items, but you just have to set Enabled and Visible to false in your XML. here is an example:

    <?xml version="1.0" encoding="UTF-8"?>
    <
    customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
     <contextMenus>
      <
    contextMenu idMso="ContextMenuFolder">
       <
    button idMso="FolderPropertiesContext"
               enabled="false"
               visible="false"/>
      </
    contextMenu>
     </
    contextMenus>
    </
    customUI>

    I tried this out and it seemed to work fine. This code hides the "Properties" menu option.  There is one thing that I am not yet sure of. If you want to dynamically specify this visibility, I am not sure which event you can handle. I will investigate this and reply if I can find this out in fairly short order.  Using declaritive XML is great if you know up front the IDs of all your folder etc.

     


    Norm E.


    Norm Estabrook
    Friday, February 26, 2010 9:59 PM
    Answerer

All replies

  • Your code not behaving nicely in Outlook 2010 is expected.  In Outlook 2007, you could handle the FolderContextMenuDisplay event, then iterate through the Controls collection until you find the ID of the control you want to disable. Then you could simply set the Visible and Enabled properties to false as follows:

    void
    app_FolderContextMenuDisplay(Office.CommandBar CommandBar, Outlook.MAPIFolder Folder)
    {
        foreach (Office.CommandBarControl menuItem in CommandBar.Controls)
        {
            if (menuItem.Id == 7888)
            {
                menuItem.Enabled =
    false;
                menuItem.Visible = false;
            }
        }
    }

    However, This event as well as the Commandbar object model in general has been deprecated for Outlook 2010. This means that you can still use the object model, but Microsoft makes no guarantees as to how well it will work. This article lists deprecated objects and members - Outlook 2010 Object Model Changes Since Earlier Versions.

    As you have probably concluded by reading the article you mention above, the best practice guidance for Outlook 2010 is to use Ribbon XML to customize context menus in Outlook. That article does not explicitely point out how to enable and disable items, but you just have to set Enabled and Visible to false in your XML. here is an example:

    <?xml version="1.0" encoding="UTF-8"?>
    <
    customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
     <contextMenus>
      <
    contextMenu idMso="ContextMenuFolder">
       <
    button idMso="FolderPropertiesContext"
               enabled="false"
               visible="false"/>
      </
    contextMenu>
     </
    contextMenus>
    </
    customUI>

    I tried this out and it seemed to work fine. This code hides the "Properties" menu option.  There is one thing that I am not yet sure of. If you want to dynamically specify this visibility, I am not sure which event you can handle. I will investigate this and reply if I can find this out in fairly short order.  Using declaritive XML is great if you know up front the IDs of all your folder etc.

     


    Norm E.


    Norm Estabrook
    Friday, February 26, 2010 9:59 PM
    Answerer
  • Ok figured it out. Just the GetVisible callback. The callback signature contains a control. You can get the currently selected folder by grabbing the context of the control. I just posted the following blog aritcle that addresses this specific issue - http://blogs.msdn.com/vsto/archive/2010/03/12/show-and-hide-context-menu-items-in-outlook-2010-norm-estabrook.aspx.
    Norm Estabrook
    • Proposed as answer by Dan Slacker Friday, March 19, 2010 3:41 PM
    Friday, March 12, 2010 10:33 PM
    Answerer
  • Hi Norm,

    Thank you for posting your article. It's very helpful. I just tried your code and I have a problem. I hope you can point me in the right direction.

    Here is the problem:
    I put a breakpoint in IsVisible and I noticed that it doesn't fire for every folder. In fact it seems like it fires only twice: once for Inbox and once for the first folder you right click on other than Inbox. I believe it's the cause of the problem I experience. Here are the repro steps:
    1) Start Outlook
    2) Right-click Inbox - Properties are hidden as expected (breakpoint is hit as well if you're in debug mode)
    3) Right-click Drafts - Properties are visible as expected (breakpoint is hit as well if you're in debug mode)
    4) Left-click Drafts to select the folder
    5) Right-click Inbox - Properties are visible! (and breakpoint is not hit if you're in debug mode)
    6) Right-click Drafts - Properties are not visible! (and breakpoint is not hit if you're in debug mode)

    I suspect I need to force context menu to refresh in these cases, but I'm not sure how and when. I've tried using InvalidateControlMso on FolderSwitch, but it didn't seem to force IsVisible method to fire. Am I doing something wrong?

    I also tried to hide some other menu items and I could hide almost all of them except:
    "Open in New Window", "Clean Up Folder" and "Show in Favorites" in FolderPropertiesContext
    "Categorize", "Find Related", "Quick Steps", "Move", "OneNote" and "Junk" in ContextMenuMailItem

    Do I need to do something different to hide these items?

    Thanks,
    Victor
    Saturday, March 13, 2010 12:19 AM
  • Very interesting. You are right. Mine behave the same way. Ok. I finally got something to work. But in order to do it, I had to fall back on the deprecated FolderContextMenuDisplay event.  Although this event is deprecated, it appears to work pretty reliably for Outlook 2010 (unlike the command bar object model). Here is what I did:

    First: Do everything I showed in the blog post - http://blogs.msdn.com/vsto/archive/2010/03/12/show-and-hide-context-menu-items-in-outlook-2010-norm-estabrook.aspx.

    Next: Ensure that you have access to the RibbonUI object in your ThisAddIn class.  I created a property in the ThisAddIn class as follows:

    Office.IRibbonUI ribbonUI;
    public Office.IRibbonUI
    RibbonUI
    {
        get { return
    ribbonUI; }
        set { ribbonUI = value
    ; }
    }

    Next: set that property in the Ribbon_Load method of your Ribbon1.cs file as follows:

    public
    void Ribbon_Load(Office.IRibbonUI ribbonUI)
    {
        this.ribbon = ribbonUI;
        Globals.ThisAddIn.RibbonUI = ribbonUI;
    }

     

     

    Finally: In your ThisAddIn class, handle the FolderContextMenuDisplay event by invalidating the "FolderPropertiesContext" control as follows:

    Outlook.
    Application app;
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        app =
    this.Application;
        app.FolderContextMenuDisplay +=
    new
        Outlook.ApplicationEvents_11_FolderContextMenuDisplayEventHandler(app_FolderContextMenuDisplay);

    }

     

     

    void app_FolderContextMenuDisplay(Office.CommandBar CommandBar, Outlook.MAPIFolder Folder)
    {
        RibbonUI.InvalidateControlMso(
    "FolderPropertiesContext");
    }


    This seemed to work well for me. Please let me know how it worked for you. I will update the blog post with this info.  Thanks for the heads up!


    Norm Estabrook
    Tuesday, March 16, 2010 6:26 PM
    Answerer
  • Hi there,

    I am also looking for solution to add commands, enable/disable exiting commnds to/on context menu in Outlook 2010.

    I am supprised to learn that FolderContextMenuDisplay is a deprecated event for OL2010, and does not work well as expected.

    However the big problem for OL2010 ribbon xml solution is that you cannot add commands to context menu dynamically except using dynamic menu. It is a problem for ribbon xml in general that there is no way to add items to ribbon after the ribbon xml is returned to outlook during addin loading process.

    Why deprcate a funtion without a  better replacement.

    Do you think the OL2010 final version will have fully functional Commandbar.

     

    Thanks

    jhou

    Friday, April 23, 2010 3:36 PM
  • 
    What you see now is what you'll get. The ribbon context menus are what you're supposed to be using. If the Outlook 2007 context stuff works it's unsupported, so I wouldn't rely on it myself.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm
     
     
    "jhou" <=?utf-8?B?amhvdQ==?=> wrote in message news:e278a473-6238-42e4-a9cf-bca4fffdc50a...

    Hi there,

    I am also looking for solution to add commands, enable/disable exiting commnds to/on context menu in Outlook 2010.

    I am supprised to learn that FolderContextMenuDisplay is a deprecated event for OL2010, and does not work well as expected.

    However the big problem for OL2010 ribbon xml solution is that you cannot add commands to context menu dynamically except using dynamic menu. It is a problem for ribbon xml in general that there is no way to add items to ribbon after the ribbon xml is returned to outlook during addin loading process.

    Why deprcate a funtion without a  better replacement.

    Do you think the OL2010 final version will have fully functional Commandbar.

     

    Thanks

    jhou


    Ken Slovak MVP - Outlook
    Friday, April 23, 2010 5:32 PM
  • I was also quite surprised to find that code I wrote to remove/hide context menu items just "didn't work", so I'm very pleased to have found this article!

    I've been able to achieve almost all I need to now by customising the ribbon XML, but I just can't seem to make the "Share" menu nor its two child items, "Share (folder type)" & "Folder Permissions", not be visible.

    The Excel spreadsheet that you provided a link to doesn't seem to have some control id's in there, but I managed to find most of what I was looking for (not shown in my fragment below becuase they're working fine) by customising the ribbon, then exporting those customisations to a file & doing a little "translation" where required. "Sharing Permissions" seems to be the id I need, along with "Share(folder type)Folder", but neither of these make the corresponding context menu items be able to be made not visible.

    Here's a fragment of the XML I'm using:

    <button idMso="FolderPropertiesContext" getVisible="showFolderOptions"/>
    <button idMso="SharingPermissions" getVisible="showFolderOptions"/>
    <button idMso="ShareNotesFolder" getVisible="showFolderOptions"/>

    The first one works perfectly, the second two seem to have no effect. Any help would be greatly appreciated.

    Thanks,

    Yann

    Wednesday, October 27, 2010 6:40 AM
  • The idMso for sharing a Calendar folder is "ShareCalendarFolder", for a Tasks folder it's "ShareTaskFolder", etc. That's right from the Excel sheet with the Explorer ribbon information. Sharing Permissions, oddly enough, is "SharingPermissions", also right there in that Excel sheet.
     
    Normally to control properties of a built-in ribbon control you use the <command> tag to identify the control and to set whatever callbacks you want on that control. See this article for information on repurposing built-in ribbon controls: http://msdn.microsoft.com/en-us/magazine/cc163469.aspx

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm
     
     
    "Yann Duran" <=?utf-8?B?WWFubiBEdXJhbg==?=> wrote in message news:7b6bf61d-1b21-4f82-afac-47543362c942...

    I was also quite surprised to find that code I wrote to remove/hide context menu items just "didn't work", so I'm very pleased to have found this article!

    I've been able to achieve almost all I need to now by customising the ribbon XML, but I just can't seem to make the "Share" menu nor its two child items, "Share (folder type)" & "Folder Permissions", not be visible.

    The Excel spreadsheet that you provided a link to doesn't seem to have some control id's in there, but I managed to find most of what I was looking for (not shown in my fragment below becuase they're working fine) by customising the ribbon, then exporting those customisations to a file & doing a little "translation" where required. "Sharing Permissions" seems to be the id I need, along with "Share(folder type)Folder", but neither of these make the corresponding context menu items be able to be made not visible.

    Here's a fragment of the XML I'm using:

    <button idMso="FolderPropertiesContext" getVisible="showFolderOptions"/>
    <button idMso="SharingPermissions" getVisible="showFolderOptions"/>
    <button idMso="ShareNotesFolder" getVisible="showFolderOptions"/>

    The first one works perfectly, the second two seem to have no effect. Any help would be greatly appreciated.

    Thanks,

    Yann


    Ken Slovak MVP - Outlook
    Wednesday, October 27, 2010 1:48 PM
  • Sample solution or code to download no eh?

    Friday, November 16, 2012 2:14 PM