add menu in outlook using c#.net in plugin application

In this post, we will discuss how to add a menu in outlook using C#.Net for plugin application. Also, you can check out my previous posts on:
For this you need to create c#.net outlook 2007 adding projects and here is a small brief by which you can create outlook add-in project.
From Visual Studio 2008 File -> New -> Project  From the New Project Dialog box Expand Visual C# then Office then Click on 2007 and the select Outlook 2007 Add-in from the Visual Studio installed templates. By doing this you will successfully able to create the Project. And in the add-in project, there will be a ThisAddIn.cs class. This class will be responsible for adding menus. Here is the code:
public partial class ThisAddIn
{
        private Office.CommandBarButton buttonHelp;
        private Office.CommandBarButton buttonFeedback;
        private Office.CommandBarButton buttonAbout;
        private string menuTag = “AspDotNetHelp”;
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
         //Search the menu and delete it if found
                    RemoveMenubar();
                    //Method to create new menu
                    AddMenuBar();
    }
          private void RemoveMenubar()
           {
            // If the menu already exists, remove it.
            try
            {
                Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
                    this.Application.ActiveExplorer().CommandBars.ActiveMenuBar.
                    FindControl(Office.MsoControlType.msoControlPopup,
                    missing, menuTag, true, true);
                if (foundMenu != null)
                {
                    foundMenu.Delete(true);
                }
            }
            catch (System.Exception ex)
            {
            }
         }
     private void AddMenuBar()
            {
    Account acc = new Account();
     menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                //Define the new Menu Bar into the old menu bar
                newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(
                    Office.MsoControlType.msoControlPopup, missing,
                    missing, missing,true);
                //If I dont find the newMenuBar, I add it
                if (newMenuBar != null)
                {
                    newMenuBar.Caption = “AspDotNetHelp”;
                    newMenuBar.Tag = menuTag;
                    buttonAbout = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                    buttonAbout.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
                    buttonAbout.Caption = “About AspDotNetHelp”;
                    buttonAbout.Enabled = false;
                    // buttonAbout.FaceId = 3737;
                    //buttonAbout.Tag = “c1”;
                    buttonFeedback = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                    buttonFeedback.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
                    buttonFeedback.Caption = “Feedback”;
                    buttonFeedback.Enabled = false;
                    // buttonFeedback.FaceId = 3737;
                    // buttonFeedback.Tag = “c2”;
                    buttonHelp = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                    buttonHelp.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
                    buttonHelp.Caption = “Help”;
                    buttonHelp.Enabled = false;
                    // buttonHelp.FaceId = 3737;
                    //buttonHelp.Tag = “c3”;
 newMenuBar.Visible = true;
}
 menuBar.Visible = true;
//You can also add event handlers for the menus like
buttonHelp.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonHelp_Click);
    }
}
If you will run this code then a new menu will appear help menu in Outlook.

You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply