title: How to position Outlook 2007/2010 VSTO Context Menu Button?
body: <p>I have an Outlook 2007/2010 add-in where I have successfully added a context-menu button to the explorer. The button itself is displayed correctly and working fine however I am unable to position it above the built-in controls on the context-menu, it is always added to the bottom. I have created the same button using VSTO 3.0 for an Outlook 2003 add-in and the same code creates a button that is at the top of the context menu above the 'Open' button. </p>
  
  <p>My code is below </p>
  
  <pre class="lang-cs prettyprint-override"><code> void Application_ItemContextMenuDisplay(CommandBar CommandBar, Selection Selection)
      {
          if (Selection.Count != 1) return;
  
          CommandBarControl rootButton = CommandBar.Controls.Add(MsoControlType.msoControlButton, Type.Missing, "Create Heat Call", 1, Type.Missing);
  
          CommandBarButton button = (CommandBarButton)rootButton;
  
          button.BeginGroup = true;
          button.Tag = "CreateHeatCall";
          button.Caption = "Create Heat Call";
          button.Style = MsoButtonStyle.msoButtonIconAndCaption;
          button.Visible = true;
  
          button.Picture = GetImage();
          button.Mask = GetImageMask();
  
          selection = Selection;
  
          ((CommandBarButton)rootButton).Click += new _CommandBarButtonEvents_ClickEventHandler(ThisAddIn_Click);
  
      }
  </code></pre>
  
  <p>I have tried playing around with the 'Before' parameter of the CommandBar.Controls.Add() method to no avail. I am suspecting the problem is that the ItemContextMenuDisplay event is being fired before the other built-in controls are added to the context menu, whereas the Outlook 2003 add-in button is being created in a method that is fired by the Explorer.CommandBars.OnUpdate event which doesn't exist in the VSTO 4.0 Explorer object.</p>
  
  <p>Is it possible to add a button that isn't on the bottom of the context menu in VSTO 4.0 for Outlook 07/10?</p>