无法使用开始时间过滤Outlook AppointmentItem

时间:2013-03-20 07:29:45

标签: c# outlook

这是我尝试在Outlook日历中找到约会:

var calendar = outlookApplication.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderCalendar);

if (calendar == null || calendar.Items == null)
{
   return null;
}

DateTime appointmentStart = new DateTime(2013, 04, 02, 10, 0 ,0);

string filter = string.Format("[Start] = '{0}'", appointmentStart );
var calendarItems = calendar.Items.Restrict(filter);

这样我就无法在日历中找到Appointmen,但我在2013年4月2日10:00:00找到了一个。

2 个答案:

答案 0 :(得分:1)

查看this example from MSDN,似乎日期/时间未在filter字符串中正确格式化:

string.Format("[Start] = '{0}'", appointmentStart);

返回[Start] = '02/04/2013 10:00:00',而

string.Format("[Start] = '{0}'", appointmentStart.ToString("g"));

返回[Start] = '02/04/2013 10:00'

请注意,此输出将取决于系统文化(在我的情况下为fr-FR),这对我来说很有意义,因为Outlook应该使用相同的。

有关日期和时间格式字符串的更多信息,请on MSDN also

答案 1 :(得分:1)

http://social.msdn.microsoft.com/Forums/en-US/outlookdev/thread/8a8d6c59-20f4-4aeb-be0d-bfdc7b414611?prof=required回答:

搜索日期/时间值时,请勿使用“=”。由于四舍五入错误,你永远不会得到匹配。使用范围,例如(开始>值 - 1分钟)和(开始<值+ 1分钟)。或者,更好的是,通过其条目ID(Namespace.GetItemfromID)打开约会或者通过其他属性(例如主题)进行搜索。