Outlook 2010: How to get a list of all appointments, including recurrences

梦想与她 提交于 2019-12-11 05:03:13

问题


I was trying to list all appointments in the default folder, like so:

Outlook.MAPIFolder calendarFolder = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items outlookCalendarItems = calendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = true;

List<Outlook.AppointmentItem> lst = new List<Outlook.AppointmentItem>();

foreach (Outlook.AppointmentItem item in outlookCalendarItems)
{
    lst.Add(item);
}

This lists all the appointments, except the recurring appointments - it only lists the first ocurrence. Is there a way to add all recurrences to this list?


回答1:


Try using the AppointmentItem.GetRecurrancePattern method (and RecurrencePattern type) off the appointment item, then you can iterate over them.

An example of getting a single occurrence can be found here:

private void CheckOccurrenceExample()
{
    Outlook.AppointmentItem appt = Application.Session.
        GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).
        Items.Find(
        "[Subject]='Recurring Appointment DaysOfWeekMask Example'")
        as Outlook.AppointmentItem;
    if (appt != null)
    {
        try
        {
            Outlook.RecurrencePattern pattern =
                appt.GetRecurrencePattern();
            Outlook.AppointmentItem singleAppt =
                pattern.GetOccurrence(DateTime.Parse(
                "7/21/2006 2:00 PM"))
                as Outlook.AppointmentItem;
            if (singleAppt != null)
            {
                Debug.WriteLine("7/21/2006 2:00 PM occurrence found.");
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }
}



回答2:


If you sort by start time, you can then use the IncludeRecurrences property to get all appointment items. One word of caution - if you have recurring appointments that don't have an end, you'll get an infinite loop - so be sure and test for an end date.

See: https://msdn.microsoft.com/en-us/library/bb220097(v=office.12).aspx



来源:https://stackoverflow.com/questions/6425776/outlook-2010-how-to-get-a-list-of-all-appointments-including-recurrences

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!