Outlook过滤项目-获取一周范围内的所有定期约会
本文关键字:约会 范围内 项目 过滤 获取 一周 Outlook | 更新日期: 2023-09-27 18:13:58
我试图在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中显示的一周范围内的所有循环约会?
必须使用递归模式把这个放到你的循环中:
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()); } }
看到这个查看更多信息