循环遍历日历中的所有约会

本文关键字:约会 遍历 日历 循环 | 更新日期: 2023-09-27 18:12:24

是否可以遍历主日历中的每个约会并检索其所有详细信息(如subject等)?

循环遍历日历中的所有约会

尝试阅读-> http://msdn.microsoft.com/en-us/library/office/dd633700%28v=exchg.80%29.aspx您需要创建一个搜索过滤器

searchFilter.SearchFilterCollection searchFilter = new SearchFilter.SearchFilterCollection();
searchFilter.Add(new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, new DateTime(1999, 1, 1)));

创建项目视图

ItemView view = new ItemView(20);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.AppointmentType);

发送请求

FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, searchFilter, view);

遍历结果

foreach (Item item in findResults.Items)
{
    Appointment appt = item as Appointment;
}

这是可能的。就在几天前,我设法做到了这一点。下面是我如何做到这一点的代码。首先,您必须获得日历文件夹,然后在该文件夹的日历上创建一组约会的视图。然后,您可以在文件夹中搜索所有约会并遍历它们。

Appointment existingAppointment = null;
DateTime startDate = (DateTime.Now).AddDays(-30);
DateTime endDate = (DateTime.Now).AddDays(60);
const int NUM_APPTS = 9999999;
Mailbox mb = new Mailbox("youremail@email.com"); 
FolderId calendarsFolder = new FolderId(WellKnownFolderName.Calendar, mb);
CalendarFolder calendarFolder = CalendarFolder.Bind(service, calendarsFolder);
// Set the calendar view as 30 days before dateTimeNow and 60 days after
CalendarView calendarView = new CalendarView(startDate, endDate, NUM_APPTS);
// Set the appointment properties for the calendar view search
PropertySet prop = new PropertySet(BasePropertySet.FirstClassProperties, extendedPropertyEventID)
    {ItemSchema.ItemClass,
    ItemSchema.Id,
    ItemSchema.Subject,
    AppointmentSchema.Subject,
    };
calendarView.PropertySet = prop;
// Search for all appointments in the main calendar folder
FindItemsResults<Appointment> findAppointmentsResults = calendarFolder.FindAppointments(calendarView);
// Loop through all the appointments in view
foreach (Appointment appointment in findAppointmentsResults)
{
    // Do stuff with the appointment
}