简体   繁体   English

Exchange EWS获取房间日历

[英]Exchange EWS Get calendar for room

I'm trying to get all the meetings for a specific room, perhaps I'm going down the wrong road but so far the most promising results are produced when I impersonate the room and then get a calendar view - the problem is that for each calendar entry the Subject contains the name of the user and not the actual meeting subject. 我正在尝试为特定会议室召开所有会议,也许我走错了路,但到目前为止,当我模拟会议室并获得日历视图时,最有希望的结果是产生的-问题是每个会议室日历条目, 主题包含用户名,而不是实际的会议主题。 Eg instead of the Subject data member containing 'Budget Meeting', it contains 'Bob Smith'. 例如,不是包含“预算会议”的主题数据成员,而是包含“鲍勃·史密斯”。

Is there a better way to get a list of calendar entries for a specific room? 是否有更好的方法来获取特定房间的日历条目列表? Here is my code: 这是我的代码:

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();
}

If you want to try another approach, you can get all of the appointments and then filter on location: 如果您想尝试另一种方法,则可以获取所有约会,然后按位置进行过滤:

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);

Now all you need to do is filter on folder type, get all the items, and then filter on room: 现在,您需要做的是根据文件夹类型进行筛选,获取所有项目,然后根据房间进行筛选:

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. 

That might not be copy-pastable, since I just typed it out right now, but I hope it's enough to get the idea across. 这可能不是复制可粘贴的,因为我现在刚刚将其键入,但是我希望它足以使想法得到传播。 You end up doing a little more work on your end but hopefully you also end up with the ability to check for appointment.Subject, appointment.Start|End.ToUniversalTime(), etc. 您最终需要做更多的工作,但希望您最终还可以检查约会。主题,约会.Start | End.ToUniversalTime()等。

Here is the working code: 这是工作代码:

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();
        }
    }
}

By default Exchange replaces the Subject with the Organizer's Name when sending the appointment to the Room resource. 默认情况下,在将约会发送到会议室资源时,Exchange用组织者的名称替换主题。 This can be disabled via Exchange Management Console with the below command, to preserve the subject 可以使用以下命令通过Exchange管理控制台将其禁用,以保留主题

Set-CalendarProcessing -Identity <RESOURCEMAILBOX> -DeleteSubject $False -AddOrganizerToSubject $False

Reference : https://support.microsoft.com/en-us/help/2842288/resource-mailbox-s-calendar-shows-the-organizer-s-name-instead-of-the 参考: https : //support.microsoft.com/zh-cn/help/2842288/resource-mailbox-s-calendar-shows-the-organizer-s-name-instead-of-the

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM