遍历日历中的所有约会

时间:2014-07-10 14:00:38

标签: c# exchangewebservices

是否可以遍历主日历中的每个约会并检索所有细节,如主题等?

2 个答案:

答案 0 :(得分:2)

尝试阅读 - > 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;

}

答案 1 :(得分:1)

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

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
}