MenuItem for Outlook ContextMenu



Last project I was working on had lot of customisation for Outlook 2003 and its integration with MOSS (Sharepoint 2007). Its altogether a unique experience working with Outlook object model and creating a custom outlook plugin.

 

Following is a small snippet for adding or manipulating context menu within outlook explorer.

 


//get outlook explorer object


private Outlook.Explorer actExplorer = this.ApplicationObject.Application.ActiveExplorer();


//get instance of all command bars


private CommandBars cmdBars = actExplorer.CommandBars;


cmdBars.OnUpdate += new _CommandBarsEvents_OnUpdateEventHandler(CommandBars_OnUpdate);


/// <summary>


/// Implements the OnUpdate event for outlook command bars.


/// </summary>


private void CommandBars_OnUpdate()


{


      foreach (CommandBar cmdBar in actExplorer.CommandBars)


      {


            if (cmdBar.Name == "Context Menu")


            {


                  //remove protection


                  MsoBarProtection oldProtection = cmdBar.Protection;


                  cmdBar.Protection = 0;


 


                  //create custom menu item


                  CommandBarButton checkInMenuItem = (CommandBarButton)cmdBar.FindControl(MsoControlType.msoControlButton, Type.Missing, "Custom Menu", Type.Missing, Type.Missing);


                  if(checkInMenuItem == null)


                  {


                        checkInMenuItem = (CommandBarButton)cmdBar.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true);


                        checkInMenuItem.Caption = "Custom Menu";


                        checkInMenuItem.Click += new _CommandBarButtonEvents_ClickEventHandler(checkInMenuItem_Click);


                  }


 


                  //set protection level


                  cmdBar.Protection = oldProtection;


            }


      }


}

Skip to main content