Microsoft.Office.Interop.Outlook.Items.Restrict – 无法正常工作

我可以拉电子邮件,浏览它们,将它们标记为已读,甚至排序。 但是,当我试图通过ReceivedTime进行限制时,它似乎不起作用。 无论我输入什么日期/时间,我什么也得不回。我知道当我删除限制时,基于Sort工作,ReceivedTime是有效的。 有什么建议?

Application app = new Application(); NameSpace outlookNs = app.GetNamespace("MAPI"); Microsoft.Office.Interop.Outlook.Folders folders = outlookNs.Folders[ohOptions.PSTName].Folders Microsoft.Office.Interop.Outlook.Items items = folders["Inbox"].Items; DateTime dt = DateTime.Now.Subtract(new TimeSpan(1,0,0)); items = items.Restrict("[ReceivedTime] > '" + dt.ToString("MM/dd/yyyy hh:mm:ss tt") + "'"); items.Sort("[ReceivedTime]", OlSortOrder.olAscending); foreach (MailItem item in items) { String from = item.SenderEmailAddress; } 

发现了问题。 只用了三天,因为似乎没有任何提及这些日期/时间的格式。 它似乎不喜欢秒或AM / PM在那里。 使用军事时间并剥离秒可以使其正常工作。

 items = items.Restrict("[ReceivedTime] > '" + dt.ToString("MM/dd/yyyy HH:mm") + "'"); 

确保当前的区域设置日期格式真的是MM / dd / yyyy,而不是dd / MM / yyyy。