Outlook Filter Items - Get all recurring appointments in a week range

扶醉桌前 提交于 2019-12-30 07:07:05

问题


I'm trying to get all appointments in outlook in week range, but reoccurring appointments are not showing up.

Here is the code:

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

How do I get all of the recurring appointments that are displayed in Outlook for a week range?


回答1:


You have to use recurrence pattern Put this inside your loop:

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

see this for more info



来源:https://stackoverflow.com/questions/8043633/outlook-filter-items-get-all-recurring-appointments-in-a-week-range

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