Outlook Interop提供了不同的结果
我使用Outlook-Interop从不同日历中读取一些事件并在大屏幕上显示它们。在我的机器上,一切正常(Outlook 2010,Win7 x64),但在客户端的电脑上(Outlook2003,Win XP),该程序没有找到所有约会。如果我添加了一些用于调试的复选框,可以在8到12个约会(12应该找到)之间找到并且没有总是6.我不知道发生了什么问题,请帮助我。Outlook Interop提供了不同的结果
下面的代码:
this.Appointments = new List<AppointmentItem>();
foreach (MAPIFolder folder in this.SelectedCalendars)
{
foreach (object app in folder.Items)
{
if (app is AppointmentItem && ((AppointmentItem)app).Start.Date == DateTime.Now.Date)
{
this.Appointments.Add(((AppointmentItem)app));
}
}
}
this.Appointments.Sort(
delegate(AppointmentItem App1, AppointmentItem App2)
{
return App1.Start.CompareTo(App2.Start);
});
更新
我有一些新的信息。得到这个例外。任何想法如何处理?
(我从德国到英语翻译,希望你能理解;))
The COM-Object of the type "System.__ComObject" couldn't be changed to the Interfacetype "Microsoft.Office.Interop.AppointmentItem. This procedure couldn't be run, because the Queryinterface-Call to the COM-Component for the interface with IID "{00063033-0000-0000-C000-000000000046}" couldn't be run because of the following error: Interface not supported (Exception _HRESULT:0x80004002 (E_NOINTERFACE)).
这可能是其失败的COM对象的迭代器。
请问,如果你重新写你的工作循环调用GetFirst()
和GetNext()
明确:
object app = folder.Items.GetFirst();
while (app != null)
{
if (app is AppointmentItem && ((AppointmentItem)app).Start.Date == DateTime.Now.Date)
{
this.Appointments.Add(((AppointmentItem)app));
}
app = folder.Items.GetNext();
}
您也可以尝试筛选的开始日期项目集合。
var items = folder.Items.Restrict("[Start] < '01/31/2009 00:00 AM' and [Start] >= '01/30/2009 00:00 AM");
确保您绑定到Office Interops的2003版本,该版本应该向前兼容。
已经选中。为了好玩,我也尝试了v14并获得了相同的结果(FYI) – 2010-08-19 22:41:29
听起来不错。我会试一试!可能需要1-2天... – 2010-07-12 12:16:52
嗯,谢谢,但这不能解决问题。我开始认为这可能是Outlook/Exchange的问题... – 2010-07-13 16:33:45
在2003年和2010年,folder.Items.Count的数字是否相同? – 2010-07-14 06:23:40