Tuesday, January 25, 2011

How to trap calendar events in outlook meeting appointments in C#.Net?


Now a days I am working on a outlook plugin application where I am in need to catch up the events of the Calendar folder. I need to save the meeting details into our sql server database. I have followed http://adriandev.blogspot.com/2008/01/listening-to-calendar-events-with.html  link first to catch up the events But after that I am doing as the following and catching of the events. But exception case incase of delete events because in that case we can not able to catch the GlobalAppointmentID. So I am doing a differently. Still I am missing of something and you are wel come to give solutions for this.  Here is the code details Hope may be it will be helpful to you.
using Outlook = Microsoft.Office.Interop.Outlook;
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);
        }
}

No comments:

Post a Comment