如何获得所有约会,包括私人约会?

时间:2014-04-14 09:05:02

标签: c# outlook

我想列出特定时间范围内的所有Outlook预约时间,我只对约会的开始和结束时间感兴趣。

到目前为止我正在使用此代码:

DateTime startTime = DateTime.Now.AddDays(2);
DateTime endTime = DateTime.Now.AddDays(3);

var outlookApplication = new Outlook.Application();
Outlook.NameSpace outlookNamespace = outlookApplication.GetNamespace("MAPI");

var recip = outlookNamespace.CreateRecipient("<valid contact>");

if (recip.Resolve())
{
    var calendarItems = outlookNamespace.GetSharedDefaultFolder(recip, OlDefaultFolders.olFolderCalendar).Items;
    calendarItems.IncludeRecurrences = true;

    var filter = String.Format("[Start] >= '{0}' And [End] < '{1}'", startTime.ToShortDateString(), endTime.ToShortDateString());

    calendarItems.Sort("[Start]");
    calendarItems = calendarItems.Restrict(filter);

    var result = calendarItems.Cast<AppointmentItem>().Select(x => x);
}

代码检索几乎所有约会,但不检索私有约会。我怎样才能获得私人约会?

1 个答案:

答案 0 :(得分:1)

Outlook始终会从共享文件夹中筛选出私人约会,即使使用MAPI可以完全访问这些约会也是如此。如果使用Redemption是一个选项,则可以使用RDOFolder。GetActivitiesForTimeRange - 它会返回私人约会。

相关问题