How to develop an MS Outlook Addin

Rate this article
5.00 out of 5
MS Outlook is one of the popular E Mail client programs (other than web mail) people used in their day to day life. In this video tutorial, we will show you how to develop an Outlook plugin using Visual Studio and C#.NET. After going through the tutorial, the reader is advised to download and go through the source code to get an understanding of what is covered in the tutorial.


Source Code
ThisAddIn.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace MyAddin
{
    public partial class ThisAddIn
    {

        private Office.CommandBar _objMenuBar;
        private Office.CommandBarPopup _objNewMenuBar;
        private Outlook.Inspectors Inspectors;
        private Office.CommandBarButton _objButton;
        private string menuTag = "MyMenu";
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            this.MyMenuBar();
            Inspectors = this.Application.Inspectors;
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region "Outlook07 Menu"
        private void MyMenuBar()
        {
            this.ErsMyMenuBar();

            try
            {
                _objMenuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                _objNewMenuBar = (Office.CommandBarPopup)
                                 _objMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup
                                                        , missing
                                                        , missing
                                                        , missing
                                                        , false);

                if (_objNewMenuBar != null)
                {
                    _objNewMenuBar.Caption = "My Plugin";
                    _objNewMenuBar.Tag = menuTag;
                    _objButton = (Office.CommandBarButton)_objNewMenuBar.Controls.
                    Add(Office.MsoControlType.msoControlButton, missing,
                        missing, 1, true);
                    _objButton.Style = Office.MsoButtonStyle.
                        msoButtonIconAndCaption;
                    _objButton.Caption = "Hello World";
                    //Icon 
                    _objButton.FaceId = 500;
                    _objButton.Tag = "ItemTag";
                    //EventHandler
                    _objButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(_objButton_Click);
                    _objNewMenuBar.Visible = true;
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message.ToString()
                                                   , "Error Message");
            }

        }
        #endregion
        #region VSTO generated code
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        #endregion

        #region "Event Handler"
        #region "Menu Button"

        private void _objButton_Click(Office.CommandBarButton ctrl, ref bool cancel)
        {
            try
            {
                System.Windows.Forms.MessageBox.Show("Hello World");
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error " + ex.Message.ToString());
            }
        }

        #endregion

        #region "Remove Existing"

        private void ErsMyMenuBar()
        {
            // If the menu already exists, remove it.
            try
            {
                Office.CommandBarPopup _objIsMenueExist = (Office.CommandBarPopup)
                    this.Application.ActiveExplorer().CommandBars.ActiveMenuBar.
                    FindControl(Office.MsoControlType.msoControlPopup
                              , missing
                              , menuTag
                              , true
                              , true);

                if (_objIsMenueExist != null)
                {
                    _objIsMenueExist.Delete(true);
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message.ToString()
                                                   , "Error Message");
            }
        }

        #endregion

        #endregion
    }
}



Download Source Code

Joined Date :14-Nov-2012
Articles
Posted
60
Messages
Posted
3

KTS InfoTech Training division offers various short-term programming courses for Students and Professionals who are looking for a bright career in the field of Software development.

The programming video tutorials presented in this web site are taken from some of the training sessions conducted by KTS InfoTech.

You can also learn the Programming packages through Internet directly form our English Speaking Technical experts at an affordable rate.

For more details click here and submit your training requirements.




   
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments

TekTipsDownload
GateExam
Academic Projects
TekTipsExperts



 
Site optimized for IE7, 1280 X 768 and above. Copyright © 2010 - 2018 KTS InfoTech
Site Developed Using KTS WebCloud