gpt4 book ai didi

c# - Exchange EWS 获取房间日历

转载 作者:太空狗 更新时间:2023-10-29 19:43:59 24 4
gpt4 key购买 nike

我正在尝试获取特定房间的所有 session ,也许我走错了路,但到目前为止,当我模拟房间然后获得日历 View 时,会产生最有希望的结果 - 问题是对于每个日历条目,主题 都包含用户的姓名,而不是实际的 session 主题。例如。它包含“Bob Smith”,而不是包含“Budget Meeting”的 Subject 数据成员。

有没有更好的方法来获取特定房间的日历条目列表?这是我的代码:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials("bobsled@yourdomain.onmicrosoft.com", "password");
service.AutodiscoverUrl("bobsmith@yourdomain.com", RedirectionUrlValidationCallback);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "sanfrancisco@yourdomain.onmicrosoft.com");

DateTime startDate = DateTime.Now;
DateTime endDate = startDate.AddDays(30);
const int NUM_APPTS = 5;

CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

foreach (Appointment a in appointments)
{
Console.Write("Subject: " + a.Subject.ToString() + " ");
Console.Write("Start: " + a.Start.ToString() + " ");
Console.Write("End: " + a.End.ToString());
Console.WriteLine();
}

最佳答案

如果您想尝试另一种方法,您可以获取所有约会,然后按位置进行过滤:

ExchangeServices.ExchangeService exchangeService = connectToServiceWhatever(userInfo); // have working service
var folderView = new ExchangeServices.FolderView(100); // or something like 100, idunno
folderView.Traversal = ExchangeServices.FolderTraversal.Deep;
folderView.PropertySet = new ExchangeServices.PropertySet(ExchangeServices.FolderSchema.FolderClass,
ExchangeServices.FolderSchema.DisplayName, ExchangeServices.FolderSchema.TotalCount,
ExchangeServices.FolderSchema.ParentFolderId); // ... and/or whatever else you want to get - folderclass is important though.
ExchangeServices.FindFoldersResults folders = exchangeService.FindFolders(ExchangeServices.WellKnownFolderName.MsgFolderRoot, folderView);

现在您需要做的就是过滤文件夹类型,获取所有项目,然后过滤房间:

var appointments = folders.Where(f => f.FolderClass == "IPF.Appointment").SelectMany(f => exchangeService.FindItems(f.Id, new ExchangeServices.ItemView(folder.TotalCount < 5 ? folder.TotalCount : 5)).Where(a => a.Location == "Boardroom");  // or whatever room you want. 

这可能不是可复制粘贴的,因为我现在刚打出来,但我希望它足以让我理解这个想法。您最终需要做更多的工作,但希望您最终也能够检查 appointment.Subject、appointment.Start|End.ToUniversalTime() 等。

这是工作代码:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials("bobsmith@yourdomain.onmicrosoft.com", "password");
service.AutodiscoverUrl("bobsmith@yourdomain.onmicrosoft.com", RedirectionUrlValidationCallback);

var folderView = new FolderView(100); // or something like 100, idunno
folderView.Traversal = FolderTraversal.Deep;
folderView.PropertySet = new PropertySet(FolderSchema.FolderClass,FolderSchema.DisplayName, FolderSchema.TotalCount,FolderSchema.ParentFolderId); // ... and/or whatever else you want to get - folderclass is important though.

FindFoldersResults folders = service.FindFolders(WellKnownFolderName.MsgFolderRoot, folderView);
// Process each item.
foreach (Folder myFolder in folders.Folders)
{
if (myFolder is CalendarFolder)
{
var calendar = (myFolder as CalendarFolder);
// Initialize values for the start and end times, and the number of appointments to retrieve.
DateTime startDate = DateTime.Now;
DateTime endDate = startDate.AddDays(30);
const int NUM_APPTS = 15;
// 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);
// Retrieve a collection of appointments by using the calendar view.
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
foreach (Appointment a in appointments)
{
Console.Write("Subject: " + a.Subject.ToString() + " ");
Console.Write("Start: " + a.Start.ToString() + " ");
Console.Write("End: " + a.End.ToString());
Console.WriteLine();
}
}
}

关于c# - Exchange EWS 获取房间日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26064671/

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