locked
C# Outlook Add-in can't get a specific occurrence (after changing the start time) from a recurring meeting. RRS feed

  • Question

  • Hi,

    I'm having some problems on getting the occurrence from a recurring meeting after modifying the start time of a specific occurrence from the Outlook calendar, I'm using GetOccurrence method to get each occurrence from the recurrence pattern of the recurring meeting. 

    for ex.

    We have a recurring meeting from Monday to Friday, 1 PM - 2 PM, and from the Outlook calendar, right click the occurrence for Tuesday, mouse over "Open", click open occurrence, change the time to 2 PM - 3 PM and then save.

    What actually happens here if tried to get the occurrence for Tuesday using the GetOccurrence method, it throws an error but if I put back the time of Tuesday to 1 PM - 2 PM, I will be able to get the occurrence for Tuesday.

    The error message is : 

    {System.Runtime.InteropServices.COMException (0x80004005): You changed one of the recurrences of this item, and this instance no longer exists. Close any open items and try again.
       at Microsoft.Office.Interop.Outlook.RecurrencePattern.GetOccurrence(DateTime StartDate)...

    Take note that the occurrence for Tuesday was not deleted and you can actually see it from the Outlook calendar. 

    I also noticed that the icon of the occurrence for Tuesday in the Calendar, in the lower right corner changes into a rotating arrow with a slash or what we call "Exception to recurring item".

    I'm currently using C# and Outlook 2010.

    Please help.

    Thanks,

    Ben

    Thursday, July 18, 2013 1:46 AM

Answers

  • 2 possible solutions/explanations for the problem:

    1. as error message says - release all refernces to that meeting and its childs (calling marshal.finalreleasecomobject) and get it again (for example using globalappointmentid or entryid if you like) and see if it works

    2. obtain your specific occurrence by iterating Exceptions collection on Recurrencepattern object that you have.

    • Marked as answer by Quist Zhang Thursday, July 18, 2013 12:15 PM
    Thursday, July 18, 2013 7:31 AM

All replies

  • What exactly do you pass to GetOccurrence?

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

    Thursday, July 18, 2013 4:26 AM
  • The start DateTime. To be specific, it includes the date selected and the start time from the recurring meeting.

    I got the codes from this link http://stackoverflow.com/questions/8043633/outlook-filter-items-get-all-recurring-appointments-in-a-week-range).

    I have done some small modifications, here is the sample code:

    if (item.IsRecurring)
    {
                Microsoft.Office.Interop.Outlook.RecurrencePattern rp = item.GetRecurrencePattern();
                DateTime startTime = new DateTime(2011, 11, 7, item.Start.Hour, item.Start.Minute, 0);
                Microsoft.Office.Interop.Outlook.AppointmentItem recur = null;
       recur = rp.GetOccurrence(startTime);
    }

    The "recur" will have the final result.

    From this code, it actually gets the start time from the recurring meeting itself which is 1 PM but the start time set specifically for the occurrence of Tuesday is 2 PM, now that's where the problem occurs (getting the start time). The code will have the limitation when we are in this given scenario. Do you have any ideas on how we can get the specific start time of that occurrence (Tuesday)? rather than using a loop to scan it.


    Thursday, July 18, 2013 7:14 AM
  • 2 possible solutions/explanations for the problem:

    1. as error message says - release all refernces to that meeting and its childs (calling marshal.finalreleasecomobject) and get it again (for example using globalappointmentid or entryid if you like) and see if it works

    2. obtain your specific occurrence by iterating Exceptions collection on Recurrencepattern object that you have.

    • Marked as answer by Quist Zhang Thursday, July 18, 2013 12:15 PM
    Thursday, July 18, 2013 7:31 AM
  • I've tried number 2 and it works. I got the start time of the occurrence from the list of Exceptions of the recurring meeting (rp.Exceptions as it is in our sample code). Because if you changed the start time of an occurrence of the recurring meeting, it will become a so called "Exception". Thanks Damian.

    Thursday, July 18, 2013 8:25 AM