none
not getting updated time on ItemChange event on resize of appointment RRS feed

  • Question

  • Hi

    We are using VSTO Plugin 2010.  we are facing issue with resizing appointment. 

    Issue is as below (this plugin-2010 is installed on outlook 2007 ):

    Consider appointment is created at 9am to 10 am (without any attendee). When we stretch this appointment and make it 9am to 11am in the ItemChange event we are getting correct new time 9am to 11am, Which is correct.(this plugin-2010 is installed on outlook 2007 )

    Now consider appointment is created at 9am to 10 am with one attendee. When we strech this appointment and make it 9am to 11am in the ItemChange event we are getting old time 9am to 10am, Which is wrong.(this plugin-2010 is installed on outlook 2007)

    Note.:If this plugin-2010 is installed on outlook 2010 ItemChange  event gives correct time with\without attendee.

    Kindly help to resolve this issue on outlook2007.

    Regards

    Neeraj


    Neeraj


    • Edited by Neerajb Wednesday, September 24, 2014 9:10 AM
    Wednesday, September 24, 2014 8:33 AM

All replies

  • Hello Neeraj,

    Did you install the latest updates and service packs for Office 2007?

    What code do you use for checking the time in the ItemChange event?

    Wednesday, September 24, 2014 9:13 AM
  • Please find below working code

    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;
    using Microsoft.Office.Interop.Outlook;

    namespace OutlookAddIn2010
    {
        public partial class ThisAddIn
        {
            private List<string> _folderPaths = new List<string>();
            private List<Items> _calendarItems = new List<Items>();
            private List<MAPIFolderEvents_12_Event> _MAPI12Events = new List<MAPIFolderEvents_12_Event>();
            public static bool _isRescheduleProgress = false;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {

                Outlook.MAPIFolder defaultFolder = this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                Items items = defaultFolder.Items;

                _calendarItems.Add(items);
                //newCalendarFolder = defaultFolder;
                MAPIFolderEvents_12_Event mapi12Event = (MAPIFolderEvents_12_Event)defaultFolder;
                _MAPI12Events.Add(mapi12Event);
                items.ItemChange += new ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
                items.ItemAdd += new ItemsEvents_ItemAddEventHandler(items_ItemAdd);
                //ReleaseObject(defaultFolder);
                //ReleaseObject(items);
            }

            void items_ItemAdd(object Item)
            {


                //GC.Collect();
                //GC.WaitForPendingFinalizers();
                //GC.Collect();
                if (Item is AppointmentItem)
                {
                    AppointmentItem ap = ((AppointmentItem)Item);
                    //RecurrencePattern rp = ap.GetRecurrencePattern();
                    //Outlook.Exceptions ex = rp.Exceptions;
                    //ap.Save();
                    //System.Windows.Forms.MessageBox.Show(ex.Count.ToString());
                    ReleaseObject(ap);
                    //ReleaseObject(rp);
                    //ReleaseObject(ex);
                    ReleaseObject(Item);
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
            }


            void Items_ItemChange(object Item)
            {
                try
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    if (Item is AppointmentItem)
                    {
                        AppointmentItem ap = ((AppointmentItem)Item);
                        System.Windows.Forms.MessageBox.Show("Start--End : " + ap.Start + " --- " + ap.End + "\r\n" + " Start-End UTC" + ap.StartUTC + " --- " + ap.EndUTC);
                        //RecurrencePattern rp = ap.GetRecurrencePattern();
                        //Outlook.Exceptions ex = rp.Exceptions;
                        //System.Windows.Forms.MessageBox.Show(ex.Count.ToString());
                        ReleaseObject(ap);
                        //ReleaseObject(rp);
                        //ReleaseObject(ex);
                        //GC.Collect();
                        //GC.WaitForPendingFinalizers();
                        GC.Collect();
                        ReleaseObject(Item);

                    }
                }
                catch (System.Exception ex)
                { }
            }

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

            /// <summary>
            /// To release object
            /// </summary>
            /// <param name="obj">Object</param>
            public static void ReleaseObject(Object obj)
            {
                try
                {
                    int i = 1;
                    do
                    {
                        i = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    }
                    while (i > 0);
                }
                catch
                { }
                finally
                {
                    obj = null;
                }
            }


            #region VSTO generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }

            #endregion
        }
    }

    -------------------------------------------------------------------------------------

    Above code is working code created with plugin2010

    If you create appointment in calender (without attendee) and click on save and close then resize it, it will show correct new time in Item change event.

    Now consider If you creating appointment by adding attendee and click on send button, it will create appointment for you then if you resize(stretch) it, it will show wrong  old time in Item change event.

    Outlook Version:2007 (12.0.6691.5000) SP3 MSO (12.0.6683.5000)

    Regards

    Neeraj


    Neeraj


    • Edited by Neerajb Wednesday, September 24, 2014 10:20 AM
    Wednesday, September 24, 2014 9:54 AM
  • HiEugene Astafiev

    Kindly help to resolve above issue ASAP


    Neeraj


    • Edited by Neerajb Wednesday, September 24, 2014 11:57 AM
    Wednesday, September 24, 2014 11:24 AM
  • > Items items = defaultFolder.Items;

    You need to declare the items object at the global scope. You will not get any event if the object is swiped by the garbage collector.  

    Also there is no need to release an Outlook object passed as a parameter to the event handler.

    Wednesday, September 24, 2014 1:00 PM
  • Hi Eugene,


    I have modified code as you have suggested. But still not working.

    Code as below:-

    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;
    using Microsoft.Office.Interop.Outlook;

    namespace OutlookAddIn2010
    {
        public partial class ThisAddIn
        {
            private List<string> _folderPaths = new List<string>();
            private List<Items> _calendarItems = new List<Items>();
            private List<MAPIFolderEvents_12_Event> _MAPI12Events = new List<MAPIFolderEvents_12_Event>();
            public static bool _isRescheduleProgress = false;
            Items items = null;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {

                Outlook.MAPIFolder defaultFolder = this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                items = defaultFolder.Items;

                _calendarItems.Add(items);
              
                MAPIFolderEvents_12_Event mapi12Event = (MAPIFolderEvents_12_Event)defaultFolder;
                _MAPI12Events.Add(mapi12Event);
                items.ItemChange += new ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
                items.ItemAdd += new ItemsEvents_ItemAddEventHandler(items_ItemAdd);
               
            }

           

            void items_ItemAdd(object Item)
            {


                
                if (Item is AppointmentItem)
                {
                    AppointmentItem ap = ((AppointmentItem)Item);
                   
                    //ReleaseObject(ap);
                    
                    //ReleaseObject(Item);
                    //GC.Collect();
                    //GC.WaitForPendingFinalizers();
                }
            }


            void Items_ItemChange(object Item)
            {
                try
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    if (Item is AppointmentItem)
                    {
                        AppointmentItem ap = ((AppointmentItem)Item);
                        System.Windows.Forms.MessageBox.Show("Start--End : " + ap.Start + " --- " + ap.End + "\r\n" + " Start-End UTC" + ap.StartUTC + " --- " + ap.EndUTC);
                        
                        //ReleaseObject(ap);
                        
                        //GC.Collect();
                        //ReleaseObject(Item);

                    }
                }
                catch (System.Exception ex)
                { }
            }

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

            /// <summary>
            /// To release object
            /// </summary>
            /// <param name="obj">Object</param>
            public static void ReleaseObject(Object obj)
            {
                try
                {
                    int i = 1;
                    do
                    {
                        i = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    }
                    while (i > 0);
                }
                catch
                { }
                finally
                {
                    obj = null;
                }
            }


            #region VSTO generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }

            #endregion
        }
    }
    --------------------------------------------

    Kindly help to resolve this issue.

    Regards

    Neeraj


    Neeraj

    Wednesday, September 24, 2014 1:27 PM
  • Neeraj,

    I don't see anything strange in the code except GC calls. But I don't think it may cause the issue.

    Try to get a new instance of the Appointment item using the GetItemFromId method of the Namespace class. Do you see the right results there?

    Wednesday, September 24, 2014 1:41 PM
  • Hi Eugene,

    I have tried "GetItemFromId" method of the Namespace but still not working. here plugin is 2010 and installed on 2007outlook. (OS win 7)

    Modified code as below :

    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;
    using Microsoft.Office.Interop.Outlook;

    namespace OutlookAddIn2010
    {
        public partial class ThisAddIn
        {
            private List<string> _folderPaths = new List<string>();
            private List<Items> _calendarItems = new List<Items>();
            private List<MAPIFolderEvents_12_Event> _MAPI12Events = new List<MAPIFolderEvents_12_Event>();
            public static bool _isRescheduleProgress = false;
            Items items = null;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {

                Outlook.MAPIFolder defaultFolder = this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                items = defaultFolder.Items;

                _calendarItems.Add(items);
              
                MAPIFolderEvents_12_Event mapi12Event = (MAPIFolderEvents_12_Event)defaultFolder;
                _MAPI12Events.Add(mapi12Event);
                items.ItemChange += new ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
                items.ItemAdd += new ItemsEvents_ItemAddEventHandler(items_ItemAdd);
               
            }

           

            void items_ItemAdd(object Item)
            {


                
                if (Item is AppointmentItem)
                {
                    AppointmentItem ap = ((AppointmentItem)Item);
                   
                    //ReleaseObject(ap);
                    
                    //ReleaseObject(Item);
                    //GC.Collect();
                    //GC.WaitForPendingFinalizers();
                }
            }


            void Items_ItemChange(object Item)
            {
                try
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    if (Item is AppointmentItem)
                    {
                        AppointmentItem ap = ((AppointmentItem)Item);
                        System.Windows.Forms.MessageBox.Show("Start--End : " + ap.Start + " --- " + ap.End + "\r\n" + " Start-End UTC" + ap.StartUTC + " --- " + ap.EndUTC);
                        AppointmentItem ap1 = this.Application.GetNamespace("MAPI").GetItemFromID(ap.EntryID);
                        //ReleaseObject(ap);
                        
                        //GC.Collect();
                        //ReleaseObject(Item);

                    }
                }
                catch (System.Exception ex)
                { }
            }

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

            /// <summary>
            /// To release object
            /// </summary>
            /// <param name="obj">Object</param>
            public static void ReleaseObject(Object obj)
            {
                try
                {
                    int i = 1;
                    do
                    {
                        i = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    }
                    while (i > 0);
                }
                catch
                { }
                finally
                {
                    obj = null;
                }
            }


            #region VSTO generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }

            #endregion
        }
    }

    --------------------------------------------

    Kindly help to resolve this issue.

    Regards

    Neeraj


    Neeraj

    Wednesday, September 24, 2014 2:15 PM
  • >  but still not working

    What do you mean "not working"? What values do you get?

    Did you try to debug the code?

    Wednesday, September 24, 2014 2:27 PM
  • I have created appointment  at 10am to 10.30am (with one attendee) then i have stretched it  till 11.30am  then  ItemChange event get executed here i have debugged code and found same (old) time as 10 to 10.30.

    It should give me 10am to 11.30 am but AppointmentItem ap1 = this.Application.GetNamespace("MAPI").GetItemFromID(ap.EntryID);

    ap1.Start & ap1.End gives me same time 10am to 10.30am

    If i am not adding any attendee then it gives me correct time  10am to 11.30am

    This is not happening on all PC which as 2007outlook.

    Kindly help ...

    Regards

    Neeraj




    Neeraj


    • Edited by Neerajb Wednesday, September 24, 2014 2:40 PM
    Wednesday, September 24, 2014 2:39 PM
  • Unfortunately I don't have Outlook 2007 installed on the machine at the moment. Hope somebody from MSFT will test this scenario. Do you use the Exchange server in the profile? Or is it a regular POP3/SMTP account?

    Also you may consider opening a support case.

    Wednesday, September 24, 2014 4:15 PM
  • We are using Exchange server.

    How and where i should open support case?

    Kindly help .....

    Regards

    Neeraj


    Neeraj

    Thursday, September 25, 2014 5:42 AM
  • Thursday, September 25, 2014 7:01 AM
  • Hello Neeraj,

    From your posts, it appears that you’re facing this issue with Outlook 2007. Please note that the mainstream support for Outlook 2007 has ended and it is currently under extended support. Please see here. This means there will be no hotfix issued even if this issue is confirmed to be a bug in Outlook 2007.

    To narrow down the issue, there are couple of things that you should check:
    1. If the issue happens in presence of any other third party add-ins.
    2. Make sure all the machines where you’re testing this plugin have the latest Office 2007 build installed. This should rule out the possibility of different builds as a cause of the issue as you're seeing mixed results.

    Also, if you could elaborate on your user scenario and the functionality, we can try suggesting an alternate approach if possible.

    If you have managed to open a support case with us, please share the Service request number with me.

    Regards,
    Manish

    Friday, October 24, 2014 6:30 PM
  • Is using Redemption an option? It does not cache old data the way Outlook does. Something like the following will do the trick:Redemption.RDOSession session = new

    Redemption.RDOSession();
    session.MAPIOBJECT = this.Application.Session
    Redemption.RDOAppointmentIterm rAppointment = session.GetItemFromID(AppointmentItem(item).EntryID. Empty.Value, Empty.Value)
    System.Windows.Forms.MessageBox.Show("Start: " + rAppointment .Start );


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Saturday, October 25, 2014 8:50 PM