EWS get resource room bookings

i need to get all the bookings from a resource "Room" named e.g.   xxx@.x.se
using EWS
could somebody show how i can get a list off all appointments in the room.

Private Sub listRoomEvents()

        Dim service As ExchangeService = ConnectToServer(user, pass)

        Dim folderView = New FolderView(100)
        folderView.Traversal = FolderTraversal.Deep

        folderView.PropertySet = New PropertySet(FolderSchema.FolderClass, FolderSchema.DisplayName, FolderSchema.TotalCount, FolderSchema.ParentFolderId)

        Dim folders As FindFoldersResults = service.FindFolders(WellKnownFolderName.Calendar, folderView)
        ' Process each item.

        For Each myFolder As Folder In folders.Folders
            If TypeOf myFolder Is CalendarFolder Then
                Dim calendar = TryCast(myFolder, CalendarFolder)
                ' Initialize values for the start and end times, and the number of appointments to retrieve.
                Dim startDate As DateTime = DateTime.Now
                Dim endDate As DateTime = startDate.AddDays(30)
                Const NUM_APPTS As Integer = 15
                ' Set the start and end time and number of appointments to retrieve.
                Dim cView As 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.
                Dim appointments As FindItemsResults(Of Appointment) = calendar.FindAppointments(cView)
                For Each a As Appointment In appointments
                    Console.Write("Subject: " + a.Subject.ToString() + " ")
                    Console.Write("Start: " + a.Start.ToString() + " ")
                    Console.Write("End: " + a.[End].ToString())
            End If

    End Sub

Open in new window

Who is Participating?
Does this work?

Dim StartDate As DateTime = DateTime.Today
Dim EndDate As DateTime = DateTime.Today.AddMonths(2)
Dim cv As New CalendarView(StartDate, EndDate)
Dim MailboxToAccess As [String] = "user@domain.com"
Dim CalendarFolderId As New FolderId(WellKnownFolderName.Calendar, MailboxToAccess)
Dim fapts As FindItemsResults(Of Appointment) = service.FindAppointments(CalendarFolderId, cv)
If fapts.Items.Count > 0 Then
	For Each Appoint As Appointment In fapts
End If

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.