Outlook筛选项 - 获取一周范围内的所有定期约会

Dar*_*ryl 3 c# office-interop outlook-2010

我试图在周范围内获得所有约会,但重复出现的约会没有出现.

这是代码:

    var outlook = new Microsoft.Office.Interop.Outlook.Application();
    var calendar = outlook.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
    calendar.Items.IncludeRecurrences = true;

    string filter = String.Format("[Start] >= {0} And [End] < {1}",
            DateTime.Now.Date.ToString("ddddd h:nn AMPM"),
            DateTime.Now.Date.AddDays(5).ToString("ddddd h:nn AMPM"));
    Outlook.AppointmentItem appointment;
    foreach (var item in calendar.Items.Restrict(filter))
    {
        appointment = item as Outlook.AppointmentItem;
        if (appointment != null)
        {
            MessageBox.Show(appointment.Start.ToString());
        }
    }
Run Code Online (Sandbox Code Playgroud)

如何获取Outlook中显示的所有定期约会一周?

use*_*076 5

你必须使用重复模式 把它放在你的循环中:

     if (item.IsRecurring)
        {
            Microsoft.Office.Interop.Outlook.RecurrencePattern rp = item.GetRecurrencePattern();
            DateTime first = new DateTime(2011, 11, 7, item.Start.Hour, item.Start.Minute, 0);
            DateTime last = new DateTime(2011, 12, 1);
            Microsoft.Office.Interop.Outlook.AppointmentItem recur = null;



            for (DateTime cur = first; cur <= last; cur = cur.AddDays(1))
            {
                    recur = rp.GetOccurrence(cur);
                    Console.WriteLine(cur.ToLongDateString());
            }
        }
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅