簡體   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