CDOEX: How To Add Recurrence to a Single Appointment

The following CDOEX code will add indefinite weekly recurrence to an individual appointment…

public CDO.Appointment AddRecurrence(CDO.Appointment oAppt, CDO.CdoDayOfWeek day,

    int instances, CDO.CdoFrequency freq)

{

    CDO.IRecurrencePattern iRPattern;

    // Create the RecurrencePattern object.

    iRPattern = oAppt.RecurrencePatterns.Add("Add");

    iRPattern.DaysOfWeek.Add((int)day);

    iRPattern.Frequency = freq;

    if (instances != -1)

    {

        iRPattern.Instances = instances;

    }

   if ((int)freq > 3)

    {

        // Convert CDO.CdoFrequency value to recurtype:

        // recurtype: 0-Single, 1-Daily, 2-Weekly, 3-Monthly and 4-Yearly

        int recurtype = (int)freq - 3;

        oAppt.Fields["https://schemas.microsoft.com/mapi/recurtype"].Value = recurtype;

        oAppt.Fields.Update();

    }

    // Save the appointment to the organizer's calendar.

    oAppt.DataSource.Save();

    Debug.WriteLine("AddRecurrence: Organizer appointment saved.");

   

    return oAppt;

}

Notes

If the value instances passed in is -1 then the property will not be set and the recurrence pattern added would be indefinite.

If the frequency is daily, weekly, monthly, or yearly then you should also set the “https://schemas.microsoft.com/mapi/recurtype” property so that Outlook will display this appointment with the proper recurrence pattern in the “Active Appointments” calendar view.