Exchange EWS Get a calendar for a room

I'm trying to collect all the appointments for a particular room, maybe I am going on the wrong road, but so far the most encouraging results arise when I pass myself off as a room and then get a calendar view - the problem is that for each calendar entry, the Topic contains a username , not the actual topic of the meeting. For instance. instead of the Item item containing the Budget Meeting, it contains Bob Smith.

Is there a better way to get a list of calendar entries for a particular 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(); } 
+6
source share
1 answer

If you want to try a different approach, you can get all the appointments and then filter by 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 have to do is filter by folder type, get all the items, and then filter in the 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. 

This may not be compatible with copying since I just printed it right now, but I hope this is enough to change my mind. You end up doing a bit more work at your end, but hopefully you also get the opportunity to check the appointment. Subject, purpose. Start | End.ToUniversalTime (), etc.

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

Source: https://habr.com/ru/post/975897/


All Articles