none
Unable to get CalendarEventDetails of Rooms in Exchange Server RRS feed

  • Question

  •  

    I am working on getting the CalendarEventDetails of Rooms in Exchange Server. I can only get the Start Date and End Date, but I'm unable to get the Subject and Location etc. Does someone has any idea how to retrieve the complete details of the Calendar event.  Here is the code: 

     

    public static void GetRoomsCalendarDetails(ExchangeServiceBinding esb, DateTime startdate, DateTime enddate, List<EmailAddressType> listRooms)
      {
       foreach (EmailAddressType room in listRooms)
       { 
       
        MailboxData mailbox = new MailboxData();
        EmailAddress emailaddress = new EmailAddress();
        emailaddress.Address = room.EmailAddress;
        mailbox.Email = emailaddress;
        mailbox.ExcludeConflicts = false;
        globalRoomsMailBoxes.Add(mailbox);
    
       }
    
       FreeBusyViewOptionsType fbViewOptions = new FreeBusyViewOptionsType();
       fbViewOptions.TimeWindow = new Duration();
       fbViewOptions.TimeWindow.StartTime = startdate;
       fbViewOptions.TimeWindow.EndTime = enddate;
       fbViewOptions.RequestedViewSpecified = true;
       fbViewOptions.MergedFreeBusyIntervalInMinutes = 30;
       fbViewOptions.MergedFreeBusyIntervalInMinutesSpecified = true;
       fbViewOptions.RequestedView = FreeBusyViewType.Detailed;
    
       
       // Make the request.
       GetUserAvailabilityRequestType request = new GetUserAvailabilityRequestType();
       // Set the time zone of the request.
    
    
       request.TimeZone = new SerializableTimeZone();
       request.TimeZone.Bias = 480;
       request.TimeZone.StandardTime = new SerializableTimeZoneTime();
       request.TimeZone.StandardTime.Bias = 0;
       request.TimeZone.StandardTime.DayOfWeek = DayOfWeekType.Sunday.ToString();
       request.TimeZone.StandardTime.DayOrder = 1;
       request.TimeZone.StandardTime.Month = 11;
       request.TimeZone.StandardTime.Time = "02:00:00";
       request.TimeZone.DaylightTime = new SerializableTimeZoneTime();
       request.TimeZone.DaylightTime.Bias = -60;
       request.TimeZone.DaylightTime.DayOfWeek = DayOfWeekType.Sunday.ToString();
       request.TimeZone.DaylightTime.DayOrder = 2;
       request.TimeZone.DaylightTime.Month = 3;
       request.TimeZone.DaylightTime.Time = "02:00:00";
    
    
    
    
       // Add the mailboxes to the request.
       request.MailboxDataArray = globalRoomsMailBoxes.ToArray();
    
       // Add the free/busy view options to the request.
       request.FreeBusyViewOptions = fbViewOptions;   
    
    
       try
       {
        // Send the request and get the response.
        GetUserAvailabilityResponseType response = esb.GetUserAvailability(request);
        
    
        // Access free/busy information.
        if (response.FreeBusyResponseArray.Length < 1)
        {
         throw new Exception("No free/busy response data available.");
        }
        else
        {
         foreach (FreeBusyResponseType fbrt in response.FreeBusyResponseArray)
         {
          if (fbrt.ResponseMessage.ResponseClass == ResponseClassType.Error)
          {
           Console.WriteLine(string.Format("Error: {0}", fbrt.ResponseMessage.MessageText));
          }
          else
          {
     
           // TODO: Get the free/busy data and working hours.
           FreeBusyView fbv = fbrt.FreeBusyView;
           CalendarEvent [] items = fbv.CalendarEventArray;
           if (items != null)
           {
            foreach (CalendarEvent myevent in items)
            {
    
             LegacyFreeBusyType busytype = myevent.BusyType;
             CalendarEventDetails caldetails = myevent.CalendarEventDetails;
             DateTime starttime = myevent.StartTime;
             DateTime endtime = myevent.EndTime;
    
            }
           }
           
           FreeBusyViewType viewbusy = fbv.FreeBusyViewType;       
           string merge = fbv.MergedFreeBusy;
           WorkingHours workinghours = fbv.WorkingHours;
           
    
    
           
          }
         }
        }
    
       }
       catch (Exception e)
       {
        
        Console.WriteLine(e.Message);
       }
      }

     

     

    Sunday, January 30, 2011 9:24 PM

Answers

  • Have a look at the calendar setting using Get-MailboxCalendarSetting pay attention the -AddOrganizerToSubject  -DeleteSubject properties you can set these with Set-MailboxCalendarSetting see http://technet.microsoft.com/en-us/library/aa996340.aspx

    Cheers
    Glen

    • Marked as answer by Falak Mahmood Monday, January 31, 2011 5:31 PM
    Monday, January 31, 2011 2:47 AM
  • If you use Set-MailboxCalendarSetting and set the AddOrganizerToSubject property to true then the organizer will be added to the subject of the appointment which will then make it available in a GetUserAvailabilityRequest. The GetUserAvailabilityRequest is limited to only showing you the subject,time and location details if you want more information you then need to bind to the ID of the calendar appointment which is provided in the response. You might want to consider using the EWS Managed API as this will simplify the task eg there a sample in http://social.technet.microsoft.com/Forums/en-AU/exchangesvrdevelopment/thread/b3124557-6961-4fc2-a9e0-c8de5ff9580d of converting the Id into the correct format to use. If you want more details then this eg phone numbers for organizer etc you will then need to use a resolvenames operations to get that information as it isn't stored in the appointment object either. eg using the Managed API this is pretty easy (proxycode not so)

          Microsoft.Exchange.WebServices.Data.CalendarEvent ce = av.CalendarEvents[0];
          AlternateId[] ai = new AlternateId[1];
          ai[0] = new AlternateId();
          ai[0].UniqueId = ce.Details.StoreId;
          ai[0].Format = IdFormat.HexEntryId;
          ai[0].Mailbox = "user@domain";
          ServiceResponseCollection<ConvertIdResponse> cvtresp = service.ConvertIds(ai, IdFormat.EwsId);
          Appointment apt = Appointment.Bind(service, ((AlternateId)cvtresp[0].ConvertedId).UniqueId);
          NameResolutionCollection ncCol = service.ResolveName(apt.Organizer.Address, ResolveNameSearchLocation.DirectoryOnly, true);
          foreach (NameResolution nr in ncCol)
          {
            Console.WriteLine(nr.Contact.PhoneNumbers[PhoneNumberKey.BusinessPhone]);
          }
          Console.WriteLine(((AlternateId)cvtresp[0].ConvertedId).UniqueId);
    

    Cheers
    Glen

    • Marked as answer by Falak Mahmood Wednesday, February 2, 2011 12:45 PM
    Monday, January 31, 2011 10:47 PM
  • You need to use a ResolveNames Operation see http://msdn.microsoft.com/en-us/library/aa563518%28v=exchg.140%29.aspx

    Something like (but you should really try as much as possible to work this out yourself)

          ResolveNamesType rnType = new ResolveNamesType();
          rnType.ReturnFullContactData = false;
          rnType.SearchScope = ResolveNamesSearchScopeType.ActiveDirectory;
          rnType.UnresolvedEntry = "blah";
    
          ResolveNamesResponseType rnResponse = esb.ResolveNames(rnType);
          ResolutionType rt = ((ResolveNamesResponseMessageType)rnResponse.ResponseMessages.Items[0]).ResolutionSet.Resolution[0];
    
    cheers
    Glen
    • Marked as answer by Falak Mahmood Wednesday, February 2, 2011 12:45 PM
    • Unmarked as answer by Falak Mahmood Wednesday, February 2, 2011 1:01 PM
    • Marked as answer by Falak Mahmood Wednesday, February 2, 2011 1:01 PM
    Wednesday, February 2, 2011 1:48 AM

All replies

  • Note: I am able to fetch the details when I explicitly added the Caller as the delegate of this room using Exchange Management Console. Is there any other work around for this problem?
    Sunday, January 30, 2011 10:28 PM
  • Have a look at the calendar setting using Get-MailboxCalendarSetting pay attention the -AddOrganizerToSubject  -DeleteSubject properties you can set these with Set-MailboxCalendarSetting see http://technet.microsoft.com/en-us/library/aa996340.aspx

    Cheers
    Glen

    • Marked as answer by Falak Mahmood Monday, January 31, 2011 5:31 PM
    Monday, January 31, 2011 2:47 AM
  • Any idea, how can I get the Organizer's information, for e.g. Organizer name, email etc
    Monday, January 31, 2011 5:32 PM
  • If you use Set-MailboxCalendarSetting and set the AddOrganizerToSubject property to true then the organizer will be added to the subject of the appointment which will then make it available in a GetUserAvailabilityRequest. The GetUserAvailabilityRequest is limited to only showing you the subject,time and location details if you want more information you then need to bind to the ID of the calendar appointment which is provided in the response. You might want to consider using the EWS Managed API as this will simplify the task eg there a sample in http://social.technet.microsoft.com/Forums/en-AU/exchangesvrdevelopment/thread/b3124557-6961-4fc2-a9e0-c8de5ff9580d of converting the Id into the correct format to use. If you want more details then this eg phone numbers for organizer etc you will then need to use a resolvenames operations to get that information as it isn't stored in the appointment object either. eg using the Managed API this is pretty easy (proxycode not so)

          Microsoft.Exchange.WebServices.Data.CalendarEvent ce = av.CalendarEvents[0];
          AlternateId[] ai = new AlternateId[1];
          ai[0] = new AlternateId();
          ai[0].UniqueId = ce.Details.StoreId;
          ai[0].Format = IdFormat.HexEntryId;
          ai[0].Mailbox = "user@domain";
          ServiceResponseCollection<ConvertIdResponse> cvtresp = service.ConvertIds(ai, IdFormat.EwsId);
          Appointment apt = Appointment.Bind(service, ((AlternateId)cvtresp[0].ConvertedId).UniqueId);
          NameResolutionCollection ncCol = service.ResolveName(apt.Organizer.Address, ResolveNameSearchLocation.DirectoryOnly, true);
          foreach (NameResolution nr in ncCol)
          {
            Console.WriteLine(nr.Contact.PhoneNumbers[PhoneNumberKey.BusinessPhone]);
          }
          Console.WriteLine(((AlternateId)cvtresp[0].ConvertedId).UniqueId);
    

    Cheers
    Glen

    • Marked as answer by Falak Mahmood Wednesday, February 2, 2011 12:45 PM
    Monday, January 31, 2011 10:47 PM
  • Hi Glen,

     

    May thanks for the reply. Unfortunately, I'm working with the Proxy code since EWS Managed API is not supported on our SP Farm. I would appreciate if you suggest getting the organizer details using the proxy code. I believe if we set AddOrganizerToSubject  to true then we should be getting the Contact details of this user. I have no idea how to fetch the user details using its name. Do you have code for that?

    Tuesday, February 1, 2011 9:05 AM
  • Hi again,

     

    to be very frank, how to get the User detail using its username, or first name + last name using the Exchange Proxy Class.

    Tuesday, February 1, 2011 9:23 AM
  • You need to use a ResolveNames Operation see http://msdn.microsoft.com/en-us/library/aa563518%28v=exchg.140%29.aspx

    Something like (but you should really try as much as possible to work this out yourself)

          ResolveNamesType rnType = new ResolveNamesType();
          rnType.ReturnFullContactData = false;
          rnType.SearchScope = ResolveNamesSearchScopeType.ActiveDirectory;
          rnType.UnresolvedEntry = "blah";
    
          ResolveNamesResponseType rnResponse = esb.ResolveNames(rnType);
          ResolutionType rt = ((ResolveNamesResponseMessageType)rnResponse.ResponseMessages.Items[0]).ResolutionSet.Resolution[0];
    
    cheers
    Glen
    • Marked as answer by Falak Mahmood Wednesday, February 2, 2011 12:45 PM
    • Unmarked as answer by Falak Mahmood Wednesday, February 2, 2011 1:01 PM
    • Marked as answer by Falak Mahmood Wednesday, February 2, 2011 1:01 PM
    Wednesday, February 2, 2011 1:48 AM
  • Many Many thanks Glen. I have made a generalized function to perform name resolutions!
    Wednesday, February 2, 2011 4:41 PM