C#exchange服务器获取会议室预约列表

时间:2017-03-01 15:22:31

标签: c# exchange-server exchangewebservices exchange-server-2010 exchange-server-2007

我尝试使用EWS Managed API获取会议室列表, 并为每个房间查看一周的预约列表。

我看到Get room lists by using EWS in ExchangeGet appointments and meetings by using EWS in Exchange

我测试了第一个链接,我得到了0个房间 同样对于第二个链接,它给出了当前用户日历,但没有会议。

我需要3件事:

1)获取组织中的会议室列表 2)获取每个房间的会议日历(X天) 3)组织会议的每次会议。

我无法找到获取此信息的API。

1 个答案:

答案 0 :(得分:4)

经过大量搜索并感谢this post 我找到了问题#1和#2

的答案

1)获取组织中的所有会议室:

 string filter = "(&(objectClass=*)(msExchRecipientDisplayType=7))";
 //Assembly System.DirectoryServices.dll
 DirectorySearcher search = new DirectorySearcher(filter);
 List<AttendeeInfo> rooms = new List<AttendeeInfo>();  
 foreach (SearchResult result in search.FindAll())
            {
                ResultPropertyCollection r = result.Properties;
                DirectoryEntry entry = result.GetDirectoryEntry();
                // entry.Properties["displayName"].Value.ToString() will bring the room name
                rooms.Add(new AttendeeInfo(entry.Properties["mail"].Value.ToString().Trim()));                 
            }

2)获取每个房间的会议日历(2天):

List<AttendeeInfo> attend = new List<AttendeeInfo>();
foreach (AttendeeInfo inf in rooms)
     {
       attend.Clear();
       attend.Add(inf.SmtpAddress);

       AvailabilityOptions options = new AvailabilityOptions();
       options.MaximumSuggestionsPerDay = 48;
       // service is ExchangeService object contains your authentication with exchange server
       GetUserAvailabilityResults results = service.GetUserAvailability(attend, new TimeWindow(DateTime.Now, DateTime.Now.AddDays(2)), AvailabilityData.FreeBusyAndSuggestions, options);

        foreach (AttendeeAvailability attendeeAvailability in results.AttendeesAvailability)
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    if (attendeeAvailability.ErrorCode == ServiceError.NoError)
                    {
                        foreach (Microsoft.Exchange.WebServices.Data.CalendarEvent calendarEvent in
                        attendeeAvailability.CalendarEvents)
                        {
                            Console.WriteLine("Calendar event");
                            Console.WriteLine(" Starttime: " + calendarEvent.StartTime.ToString());
                            Console.WriteLine(" Endtime: " + calendarEvent.EndTime.ToString());
                            if (calendarEvent.Details != null)
                            {
                                Console.WriteLine(" Subject:" + calendarEvent.Details.Subject);

                            }
                        }
                    }
                }
            }

关于问题#3,获取此信息并不简单,因为它是私人信息,而作为普通用户,您无权查看此信息。