gpt4 book ai didi

c# - Exchange EWS Api - 按类别获取日历约会

转载 作者:太空宇宙 更新时间:2023-11-03 21:22:49 26 4
gpt4 key购买 nike

我目前正在开发一款应用程序,用于检查一个或多个用户日历中特定类别下的约会/ session 。

作为使用 EWS 的新手,我一直在尝试寻找一种解决方案,以按类别获取日历项目(约会或 session )或确定约会是否具有特定类别。到目前为止,我目前有以下代码(exService = ExchangeService 对象):

foreach (Appointment a in exService.FindItems(WellKnownFolderName.Calendar, new ItemView(int.MaxValue)))
{
//Need to check if appointment has category f.x.: "SMS"
}

有人知道实现这个的方法吗?

谢谢

最佳答案

当您查询约会时,您希望使用 FindAppointments 和日历 View 而不是使用 FindItems,这将确保扩展任何重复约会,例如参见 https://msdn.microsoft.com/en-us/library/office/dn495614(v=exchg.150).aspx

要使用类别,您需要做的就是

        DateTime startDate = DateTime.Now;
DateTime endDate = startDate.AddDays(60);
const int NUM_APPTS = 1000;

// Initialize the calendar folder object with only the folder ID.
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());

// Set the start and end time and number of appointments to retrieve.
CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);

// Limit the properties returned to the appointment's subject, start time, and end time.
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End,AppointmentSchema.Categories);

// Retrieve a collection of appointments by using the calendar view.
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + startDate.Date.ToShortDateString() +
" to " + endDate.Date.ToShortDateString() + " are: \n");
foreach (Appointment a in appointments)
{
if (a.Categories.Contains("Green"))
{
Console.Write("Subject: " + a.Subject.ToString() + " ");
Console.Write("Start: " + a.Start.ToString() + " ");
Console.Write("End: " + a.End.ToString());
}
Console.WriteLine();
}

关于c# - Exchange EWS Api - 按类别获取日历约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29508917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com