【问题标题】:Outlook Filter Items - Get all recurring appointments in a week rangeOutlook 筛选项目 - 获取一周内的所有定期约会
【发布时间】:2011-12-24 00:35:36
【问题描述】:

我正在尝试在一周范围内获取 Outlook 中的所有约会,但没有显示重复约会。

代码如下:

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

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

【问题讨论】:

    标签: c# office-interop outlook-2010


    【解决方案1】:

    你必须使用recurrence pattern 把它放在你的循环中:

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

    this 了解更多信息

    【讨论】:

    • 效果很好,除非我尝试在未安排的一天预约我得到一个例外。我已经包装了 recur = rp.GetOccurrence(cur);与 try catch 对齐,继续,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多