EWS Service.FindItems () throws an exception when using SearchFilter.IsEqualTo

Here is my code for getting some calendar items (appointments) from EWS. But this always rules out an exception.

Exception: The property cannot be used with this type of constraint.

        private void GetChangedAppointmentInformation(Appointment appointment)
        {
            try
            {
                // Save appointment details into local variables
                id = appointment.Id.ToString();
                body = appointment.Body;
                duration = appointment.Duration;
                end = appointment.End;
                bookingKey = appointment.Subject;
                subject = appointment.Subject;
                location = appointment.Location;


                ItemView view = new ItemView(1000);

                // Create a search filter that filters email based on the existence of the extended property.
                SearchFilter eq = new SearchFilter.IsEqualTo(AppointmentSchema.ICalUid, appointment.ICalUid);

                // Search the Calendar with the defined view and search filter. This results in a FindItem operation call to EWS.
                FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, eq, view);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }

      

Could you advise me on this? I have tried MSDN and several other online resources, I am still trying to figure it out.

+3


source to share


1 answer


The error is telling you that the strongly typed property you are trying to use cannot be used in a constraint. The best workaround for this is to use an equivalent extended property instead, for example to search based on an existing meeting, something like

    Appointment newAppointment = new Appointment(service);
    newAppointment.Subject = "Test Subject";        
    newAppointment.Start = new DateTime(2012, 03, 27, 17, 00, 0);
    newAppointment.StartTimeZone = TimeZoneInfo.Local;
    newAppointment.EndTimeZone = TimeZoneInfo.Local;
    newAppointment.End = newAppointment.Start.AddMinutes(30);
    newAppointment.Save();
    newAppointment.Body = new MessageBody(Microsoft.Exchange.WebServices.Data.BodyType.Text, "test");
    newAppointment.RequiredAttendees.Add("attendee@domain.com");
    newAppointment.Update(ConflictResolutionMode.AlwaysOverwrite ,SendInvitationsOrCancellationsMode.SendOnlyToAll);
    ExtendedPropertyDefinition CleanGlobalObjectId = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, 0x23, MapiPropertyType.Binary);
    PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
    psPropSet.Add(CleanGlobalObjectId);
    newAppointment.Load(psPropSet);
    object CalIdVal = null;
    newAppointment.TryGetProperty(CleanGlobalObjectId, out CalIdVal);
    Folder AtndCalendar = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar,"attendee@domain.com"));
    SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(CleanGlobalObjectId, Convert.ToBase64String((Byte[])CalIdVal));
    ItemView ivItemView = new ItemView(1);
    FindItemsResults<Item> fiResults = AtndCalendar.FindItems(sfSearchFilter, ivItemView);
    if (fiResults.Items.Count > 0) {
        //do whatever
    }

      



Should work fine

Cheers Glen

+3


source







All Articles