Powered by Blogger.

Sunday, February 23, 2014

Trap outlook calendar events in outlook meeting appointments in C#.Net



In this post we will discuss how to trap outlook calendar events in outlook meeting appointments in C#.Net. Also you can check out my previous posts on:

- Lock users who provide bad passwords in Asp.Net

- How to read recurrance Pattern of a outlook meeting using redemption using c#.net?

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

If you are working in outlook plugin application development then we need to catch the events of the calendar folder. Here the requirement is to save meeting details into SQL Server 2008 database.

But in case of delete event you will not get the GlobalAppointmentID of the meeting item. Follow below code:

using Office = Microsoft.Office.Core;
 public partial class ThisAddIn
{
        Microsoft.Office.Interop.Outlook.Application app = null;
        NameSpace ns = null;
        MAPIFolder calendar = null;
        Items appointments = null;
        private  Outlook.MAPIFolder DeletedItem;
        private  Outlook.Items itemDelete;
       private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            app = new Microsoft.Office.Interop.Outlook.Application();
            ns = app.GetNamespace("mapi");
            ns.Logon("", "", true, true);
            calendar = ns.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);

            appointments = calendar.Items;
            appointments.ItemAdd += new ItemsEvents_ItemAddEventHandler(appointments_ItemAdd);
            appointments.ItemChange += new ItemsEvents_ItemChangeEventHandler(appointments_ItemChange);
            appointments.ItemRemove += new ItemsEvents_ItemRemoveEventHandler(appointments_ItemRemove);
       }
      void itemDelete_ItemChange(object Item)
        {
            AppointmentItem appointment = (Item as AppointmentItem);
            Messageox.Show(appointment.GlobalAppointmentID);                              
        }

        void appointments_ItemRemove()
        {
            DeletedItem = ns.GetDefaultFolder(OlDefaultFolders.olFolderDeletedItems);
            itemDelete = DeletedItem.Items;
            itemDelete.ItemChange += new ItemsEvents_ItemChangeEventHandler(itemDelete_ItemChange);
        }

        void appointments_ItemChange(object Item)
        {
            AppointmentItem appointment = (Item as AppointmentItem);
            Messageox.Show(appointment.GlobalAppointmentID);
        }

        void appointments_ItemAdd(object Item)
        {
           AppointmentItem appointment = (Item as AppointmentItem);
            Messageox.Show(appointment.GlobalAppointmentID);
        }
}





0 comments

Post a Comment