locked
GetOccurrence if there is No End Date. RRS feed

  • Question

  • I have appointment item which is recurring. When some user set No end date is true,I'll change pattern end date as end of currant year and get how many time that item is recurring. But I am getting error "You changed one of the recurrences of this item, and this instance no longer exists. Close any open items and try again."

    Here is my code. Can some one help me to achieve this. I am trying getting this manually but its more time consuming.

    Outlook.AppointmentItem aitem = item as Outlook.AppointmentItem;
    if (aitem.IsRecurring == true)
                {
                    Outlook.RecurrencePattern pattern = aitem.GetRecurrencePattern();
         if (noEndDate == true)
                {
                    var patternEndDate = new DateTime(DateTime.Now.Year, 12, 31);
                    pattern.PatternEndDate = patternEndDate;
    try
                    {
                        var totalOcc = pattern.GetOccurrence(pattern.PatternStartDate);
                    }
                    catch (System.Exception ex)
                    {
                        
                        throw;
                    }
               }
    }


    chapneox

    Monday, June 30, 2014 4:01 AM

Answers

All replies

  • Does it actually occur on 12/31/2014? What is the exact recurrence pattern?


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

    Monday, June 30, 2014 4:32 AM
  • No, we can not say it is exactly occur in 12/31/2014. What i want is find how many occurrences between now and end of this year. I have to log how many task in a db. If some user not set End Date there will be unlimited issues. I want to overcome that. recurrence pattern can be any.  

    chapneox

    Monday, June 30, 2014 5:06 AM
  • You don't really have much choice if you are using the Outlook object model: you will need to calculate the occurrence dates explicitly in your code.

    If using Redemption is an option, you can use RDORecurrencePattern.GetOccurrence, which takes either a date (just like Outlook) or an integer index - you can use the latter one and retrieve the occurrences until the date is > 12/31/2014.


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

    Monday, June 30, 2014 5:11 AM
  • Thanks for your reply. I found easy way. Seems getting correct results. 

    Outlook.RecurrencePattern pattern = aitem.GetRecurrencePattern();
     Outlook.RecurrencePattern pattern2 = aitem.GetRecurrencePattern();
    
    pattern2 = pattern;
    
    pattern2.PatternStartDate = DateTime.Now;
    pattern2.PatternEndDate = patternEndDate; //year end
    
    var occurrences = pattern2.Occurrences;


    chapneox

    Monday, June 30, 2014 5:35 AM
  • But that would require you to modify the original recurrence pattern, would it not?

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

    Monday, June 30, 2014 6:10 AM
  • Also you may use the Find/FindNext and Restrict methods for getting appointments, see the following articles for more information:

    How To: Retrieve Outlook calendar items using Find and FindNext methods

    How To: Use Restrict method in Outlook to get calendar items

    Monday, June 30, 2014 9:22 AM