gpt4 book ai didi

c# - Outlook Filter Items - 获取一周范围内的所有重复约会

转载 作者:行者123 更新时间:2023-11-30 15:06:16 25 4
gpt4 key购买 nike

我试图在 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 中显示的一周范围内的所有定期约会?

最佳答案

你必须使用 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了解更多信息

关于c# - Outlook Filter Items - 获取一周范围内的所有重复约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8043633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com