繁体   English   中英

Outlook 2010:如何获取所有约会(包括重复约会)的列表

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

我试图列出默认文件夹中的所有约会,如下所示:

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);
}

这将列出所有约会,但定期约会除外-仅列出第一次出现。 有没有一种方法可以将所有重复项添加到此列表中?

如果按开始时间排序 ,则可以使用IncludeRecurrences属性来获取所有约会项目。 一个警告:如果您的定期约会没有结束,您将陷入无限循环-因此请确定并测试结束日期。

请参阅: https : //msdn.microsoft.com/zh-cn/library/bb220097(v=office.12).aspx

尝试在AppointmentItem.GetRecurrancePattern使用AppointmentItem.GetRecurrancePattern方法(和RecurrencePattern类型),然后可以对其进行迭代。

在此处可以找到一个单例的示例:

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);
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM