outlook-redemption

Attempting to use Redemption RDORecurrencePattern to get GetOccurence by index for RDOAppointmentItem items


I'm attempting to get the Start date for all meetings within the default calendar. Per the documentation (link)

I can use the index or date for GetOccurence.

When I try to use the index with the code below, gives me the first meeting occurrence twice and the middle occurrence but not the last occurrence. For Example, if I create a recurring meeting named “Redemption Test”. The meeting repeats daily for 3 days and there are no exceptions (Occurs every day effective 11/27/2023 until 11/29/2023 from 8:00 PM to 8:25 PM). I also updated the body of each occurrence in Outlook so that I'm sure my start date matches the occurrence for further validation.

With the first pass through the for loop Debug.WriteLine(apt.Body); outputs "11/27" (since I manually added it to the body). Debug.WriteLine(apt.Start); outputs "11/27/2023 8:00:00 PM" . With the second pass I get the identical results, which is unexpected. With the third pass Debug.WriteLine(apt.Body); outputs "11/28" and Debug.WriteLine(apt.Start); outputs "11/28/2023 8:00:00 PM". But I never get the third occurrence for 11/29/2023 8:00:00 PM.

private void Button_Click(object sender, RoutedEventArgs e)
    {
        RDOSession session = new RDOSession();
        session.Logon(System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, true, System.Reflection.Missing.Value, false);
        RDOFolder calendar = session.GetDefaultFolder(rdoDefaultFolders.olFolderCalendar);

        foreach (RDOAppointmentItem item in calendar.Items)
        {
            if (item.Subject != null)
            {
                if (item.Subject.Contains("Redemption Test"))
                {
                    Redemption.RDORecurrencePattern pattern = item.GetRecurrencePattern();
                    for (int i = 0; i < pattern.Occurrences; i++)
                    {
                        RDOAppointmentItem apt = (RDOAppointmentItem)pattern.GetOccurence(i);
                        Debug.WriteLine(apt.Body);
                        Debug.WriteLine(apt.Start);
                    }

If I use GetOccurence by date, for example:

                    string dt1str = "11/27/2023 8:00 PM";
                    var date1 = DateTime.Parse(dt1str);
                    string dt2str = "11/28/2023 8:00 PM";
                    var date2 = DateTime.Parse(dt2str);
                    string dt3str = "11/29/2023 8:00 PM";
                    var date3 = DateTime.Parse(dt3str);

                    RDOAppointmentItem apt1 = (RDOAppointmentItem)pattern.GetOccurence(date1);
                    Debug.WriteLine(apt1.Body);
                    Debug.WriteLine(apt1.Start);
                    RDOAppointmentItem apt2 = (RDOAppointmentItem)pattern.GetOccurence(date2);
                    Debug.WriteLine(apt2.Body);
                    Debug.WriteLine(apt2.Start);
                    RDOAppointmentItem apt3 = (RDOAppointmentItem)pattern.GetOccurence(date3);
                    Debug.WriteLine(apt3.Body);
                    Debug.WriteLine(apt3.Start);
                }
            }

This works fine, I get the expected body and start date.

I prefer to use the index as that's way easier then looking at each RecurrencePattern and calculating dates to get each occurrence start date.

Any thoughts on what might be wrong with the first snippet with the for loop?

I tried setting int i = 0 to int i = 1 but that just skips the first occurrence for 11/27. I'm using the latest version of Redemption 6.4.0.6234.


Solution

  • All Redemption collections, just like those in the Outlook Object Model, are 1 based, not 0, so the loop should be

    for (int i = 1; i <= pattern.Occurrences; i++)