Powered by Blogger.

Sunday, February 23, 2014

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

In this post we will discuss how to add menu in outlook using C#.Net for plugin application. Also you can check out my previous posts on:

- How to add menus in outlook menu bar using C#.net object model?

- Body onload function in content page in asp.net

- Working with enterprise library for data access in asp.net

For this you need to create c#.net outlook 2007 addin projects and here is a small brief by  which you can create outlook addin 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 addin 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
                    //Method to create new menu
          private void RemoveMenubar()
            // If the menu already exists, remove it.
                Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
                    missing, menuTag, true, true);
                if (foundMenu != null)
            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 appear help menu in Outlook.


Post a Comment