我正在尝试为特定房间举行所有会议,也许我会走错路,但到目前为止,当我冒充房间然后获得日历视图时,最有希望的结果会产生 - 问题是对于每个日历条目,主题包含用户的名称,而不是实际的会议主题。例如。而不是包含“预算会议”的主题数据成员,它包含“Bob Smith”。
有没有更好的方法来获取特定房间的日历条目列表?这是我的代码:
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();
}
答案 0 :(得分:3)
如果您想尝试其他方法,您可以获得所有约会,然后在位置进行过滤:
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.
这可能不是可复制的,因为我现在只是输入它,但我希望它足以让这个想法得到解决。你最终会在你的最后做一些工作,但希望你最终能够检查约会。主题,预约。开始| 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();
}
}
}
答案 1 :(得分:0)
默认情况下,Exchange会在将约会发送到Room资源时使用管理器的名称替换Subject。可以使用以下命令通过Exchange管理控制台禁用此功能,以保留主题
Set-CalendarProcessing -Identity <RESOURCEMAILBOX> -DeleteSubject $False -AddOrganizerToSubject $False