打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c#-检索当前的Outlook约会

我需要当前的约会.如果没有当前约会,则下一个甚至之前的约会.

我想使用限制来限制约会集,然后根据限制参数选择第一个约会或最后一个约会(例如,限制到在当前时间之后结束的约会或在当前时间之前开始的约会).

我遇到了需要作为参数的字符串过滤器的麻烦.

一个简单的VB示例(代码树桩):

myStart = Format(Date, "mm/dd/yyyy hh:mm AMPM")    strRestriction = "[Start] <= '" & myStart & "'"'Restrict the Items collectionSet oResItems = oItems.Restrict(strRestriction)'SortoResItems.Sort "[Start]"

我正在尝试在C#中执行相同的操作.

// Create the Outlook application.Outlook.Application oApp = new Outlook.Application();// Get the NameSpace and Logon information.// Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");Outlook.NameSpace oNS = oApp.GetNamespace("mapi");//Log on by using a dialog box to choose the profile.oNS.Logon(Missing.Value, Missing.Value, true, true);// Get the Calendar folder.Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);// Get the Items (Appointments) collection from the Calendar folder.oItems = oCalendar.Items;oItems.IncludeRecurrences = true;// THIS IS THE PROBLEM AREAString filter = "[Start] <= '"   DateTime.Now.ToString("MM/dd/yyyy hh:mm AMPM")   "'";Outlook.Items restrictedItems = oItems.Restrict(filter);// Take the last item on the list - should be current or next appointmentrestrictedItems.Sort("[Start]");Outlook.AppointmentItem oAppt = restrictedItems.GetLast();// Done. Log off.oNS.Logoff();

我想因为过滤器是一个字符串,所以日期格式需要为yyyy / mm / dd HH:mm:ss?我找不到任何有关如何操作[开始]的文档,例如将其解析为日期或其他内容.

根据日期格式,我将获得错误的约会,或者由于筛选器将所有约会排除在外而无法使用GetLast.

我看过一些示例,但是它们要么遍历约会(效率低下),要么看起来像日期格式,似乎无法信任它们返回正确的约会(例如https://social.msdn.microsoft.com/Forums/vstudio/en-US/c6a8bd21-6534-43be-b23e-1068651da92e/retrieve-appointment-items-from-outlook-2007-calendar-restrict?forum=vsto,如果使用,则似乎将日期硬编码了DateTime.Now.)

更新:我目前正在遍历如下所示.对于更有效的代码有什么建议吗?

DateTime currentTime = DateTime.Now;foreach (Outlook.AppointmentItem item in oItems){    if (item.Start <= currentTime && item.End.Subtract(new TimeSpan(0, 10, 0)) > currentTime)    {        appointmentArrayList.Add(item);    }}

解决方法:

通过遵循找到的here信息,我能够使用“ yyyy-MM-dd HH:mm”作为toString调用的格式字符串来使其工作.

希望这可以帮助.

来源:https://www.icode9.com/content-1-514901.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
时间,日期操作类 - baby69yy2000 - JavaEye技术网站
java时间格式大全
java时间格式
delphi中日期格式的设定
C#时间处理
跟烟花入门VBA之96:Application对象(十四)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服