none
Shared Calendar - PropertyChange event does not trigger RRS feed

  • Question

  • Hello Friends,

    I am working on a requirement where we need to capture any changes to a past item on shared calendar and open it explicitly. Below is my sample code - this works perfectly fine on own calendar but not on shared calendars. I see that PropertyChange event gets register properly but does not trigger in case of shared calendar. 

    Any idea if i am missing or doing anything wrong here? Is there any other way to handle this? Please advise.

    void _explorer_SelectionChange()
    {
    	if (_explorer == null || _explorer.CurrentFolder == null) return;
    	if (_explorer.CurrentFolder.DefaultItemType == OlItemType.olAppointmentItem)
    	{
    		try
    		{
    			_appointment = GetAppointmentItem(); //Gives back currently select AppointmentItem object
    			if (_appointment == null) return;
    
    			_appointment.PropertyChange += (propertyName) =>
    			{
    				_appointment.Display(false);
    			};
    		}
    		catch (Exception exception)
    		{
    			//Capture error
    		}
    	}
    }

    Thanks.


    sureshh...

    Friday, July 28, 2017 1:55 PM

Answers

  • All,

    Finally, I was able to fix this issue where look like it works consistently in both own and shared calendar items. Here is my code that works.

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.ItemLoad += Application_ItemLoad;
    }
    
    private void Application_ItemLoad(object Item)
    {
        //appItem is selected AppointmentItem
        appItem.PropertyChange += AppItem_PropertyChange;
    }

    Thanks all for your help.


    sureshh...

    • Proposed as answer by Terry Xu - MSFT Wednesday, August 2, 2017 5:46 AM
    • Marked as answer by sureshh Wednesday, August 2, 2017 1:11 PM
    Wednesday, August 2, 2017 1:52 AM

All replies

  • Hello Suresh,

    Did you try to debug the code?

    Anyway, I'd suggest releasing any COM objects in the code instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. The set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects article.

    Also you may find the Capturing AppointmentItem events in a shared calendar forum thread helpful.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Friday, July 28, 2017 2:44 PM
  • Thanks Eugene for quick response. Yes I did debug the code and see that event is getting registered properly, but never fires.

    Actually after posting this question i did look at the this thread and read through it. I understand that we need to release com objects once we are done using it. But in our case there are many outlook plugins in the firm, and each one might be using same object that our application is using; so if I use ReleaseComObject method, wouldn't it cause issues with other applications using that object?

    Also one more observation:

    Strange thing is same above code of PropertyChange event triggers fine on shared calendar, when 

    1. we do inline subject update within calendar [Select meeting, press F2 key on keyboard, update subject and hit Enter key];

    2. we drag meeting from corner to extend its time and Hit Enter key;

    but does not trigger on drag & drop operation on that complete item to save it on totally different slot.

    Also as per Capturing AppointmentItem events in a shared calendar thread, there are similar observations for Write event even after memory issues cleaned up.

    WHEN THE ITEMS ARE IN THE SHARED CALENDAR
    Even Item_Write event - Does NOT fire if I click and Drag the appointmentItem to a new time.  I have to open an Inspector Window to change the time.

    Does it mean this is actually a bug in Outlook or not supported by Outlook?


    • Edited by sureshh Friday, July 28, 2017 7:43 PM
    Friday, July 28, 2017 3:45 PM
  • Hello,

    I failed to reproduce your issue. The event works fine as common calendar after i have full permission as onwer. I am testing in Office 2016 1701 using the following code. 

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.ActiveExplorer().SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(explorer_SelectionChange);
    
            }
            void explorer_SelectionChange()
            {
                try
                {
                    Outlook.Explorer currentExplorer = this.Application.ActiveExplorer();
                    if (currentExplorer.Selection.Count > 0)
                    {
                        Object selObject = currentExplorer.Selection[1];
    
                        if (selObject is Outlook.AppointmentItem)
                        {
                            Outlook.AppointmentItem appItem =
                            (selObject as Outlook.AppointmentItem);
                            appItem.PropertyChange += AppItem_PropertyChange;                      
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(selObject);
                        selObject = null;
                        currentExplorer = null;
                    }
                }
                catch (Exception ex)
                {
    
                }
            }
            private void AppItem_PropertyChange(string Name)
            {
                System.Windows.Forms.MessageBox.Show("AppItem_PropertyChange");
            }
    

    What is your Office version? Could you reprodcue the issue in other computer with same or different Office version? Would it work if you use the my code?

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 31, 2017 8:39 AM
    Moderator
  • Hi Celeste, thanks fro the suggestion. I tried suggested code but unfortunately it did not work in my case. I am using Outlook 2010.

    With above code:

    1 - it's not working on shared calendar at all, tried on different machines with Outlook 2010

    2 - some time it worked on own calendar and some time didn't.

    This time I am also releasing com object as suggested still no luck. ReleaseComObject(selObject).

    Do you think I am missing anything else here?

    One more thing to note:

    PropertyChange event fire properly in case of SharedCalendar item only in below cases

    1- select item on shared calendar, press F2 from keyboard to edit that item, change subject and press Enter key

    2-select item on shared calendar, drag bottom end of that item to extend its end time, and press enter key

    Thanks.




    • Edited by sureshh Tuesday, August 1, 2017 7:50 PM
    Tuesday, August 1, 2017 7:39 PM
  • All,

    Finally, I was able to fix this issue where look like it works consistently in both own and shared calendar items. Here is my code that works.

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.ItemLoad += Application_ItemLoad;
    }
    
    private void Application_ItemLoad(object Item)
    {
        //appItem is selected AppointmentItem
        appItem.PropertyChange += AppItem_PropertyChange;
    }

    Thanks all for your help.


    sureshh...

    • Proposed as answer by Terry Xu - MSFT Wednesday, August 2, 2017 5:46 AM
    • Marked as answer by sureshh Wednesday, August 2, 2017 1:11 PM
    Wednesday, August 2, 2017 1:52 AM
  • Hi sureshh,

    I'm glad to hear that you have solved the issue. I suggest you mark your solution as answer to close this thread. Thanks for understanding.

    Best Regards,

    Terry

    Wednesday, August 2, 2017 5:46 AM
  • Thanks Terry. I thought generally moderator does mark as answer and so I did not do it before.

    sureshh...

    Wednesday, August 2, 2017 12:49 PM