【发布时间】:2013-07-25 23:49:05
【问题描述】:
我正在使用 Office 对象模型从 Outlook 中检索我的日历项目。我想使用 Restrict() 方法只获取今天的约会。我还想包括所有定期约会的单个实例(即并非所有重复 - 只是今天的那些)。
使用以下代码,无论日期如何,我都会收到许多(但不是全部)重复性项目,例如生日。我还有其他各种约会 - 但不是今天的约会。
我尝试了不同的日期格式,包括 2013-07-25 00:00:00,但没有运气。我研究了网络,并尝试从 VBA 脚本中复制示例 - 不走运。
感谢其他人的任何想法。
var outlook = new Application();
var calendar = outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
DateTime today = DateTime.Today, tomorrow = today.AddDays(1);
const string DateFormat = "dd/MM/yyyy HH:mm";
string filter = string.Format("[Start] >= '{0}' AND [Start] < '{1}'", today.ToString(DateFormat), tomorrow.ToString(DateFormat));
var todaysAppointments = calendar.Items.Restrict(filter);
// todaysAppointments.IncludeRecurrences = true;
todaysAppointments.Sort("[Start]");
【问题讨论】:
-
你试过这种日期格式
Mddyy h:mm tt吗?从这里:msdn.microsoft.com/en-us/library/office/… -
感谢您的建议。我试过这个并得到了相当不同的结果。使用 IncludeRecurrences=true,我刚刚得到了定期约会——比如人们的生日。将其设置为 false,我只会得到 3 个生日,而没有其他任何东西 - 而这些生日甚至不是这个月......
标签: c# calendar outlook ms-office