EWS服务在使用SearchFilter.IsEqualTo时,调用FindItems()方法会抛出异常。

3
这是我获取EWS中一些日历项(约会)的代码。但这总是抛出异常。
异常信息:该属性不能与此类型的限制一起使用。
        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);
            }
        }

您能否就此向我提供建议?我已经查阅了MSDN和其他几个在线资源,但仍在尝试弄清楚其中的问题。


请添加异常详细信息。 - Jan Köhler
1个回答

3
错误提示告诉你,你试图在限制条件中使用的强类型属性无法使用。最好的解决方法是使用等效的扩展属性,例如基于现有约会搜索的内容,可以使用以下方式:
    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
    }

应该没问题

谢谢 格伦


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接