EWS: Find contact items by email address RRS feed

  • Question

  • I'd love to be able to find a contact item within a folder.

    I've constructed the following code which forms part of a function i'm trying to implement:

                FindItemType findItemRequest = new FindItemType();
                ItemResponseShapeType responseShape = new ItemResponseShapeType();
                responseShape.BaseShape = DefaultShapeNamesType.Default;
                findItemRequest.ItemShape = responseShape;

                // Identify which folders to search
                FolderIdType[] folderIDArray = new FolderIdType[1];
                folderIDArray[0] = fldTarget; // fldTarget is passed in to the function

                // Add the folders to search to the request
                findItemRequest.ParentFolderIds = folderIDArray;

                // Add Restriction for E Mail Address
                RestrictionType iRestriction = new RestrictionType();
                IsEqualToType ieToType = new IsEqualToType();
                PathToIndexedFieldType iEmailAddress = new PathToIndexedFieldType();
                iEmailAddress.FieldURI = DictionaryURIType.contactsEmailAddress;
                iEmailAddress.FieldIndex = "0";

                FieldURIOrConstantType ciConstantType = new FieldURIOrConstantType();
                ConstantValueType cvConstantValueType = new ConstantValueType();
                cvConstantValueType.Value = "";
                ciConstantType.Item = cvConstantValueType;
                ieToType.Item = iEmailAddress;
                ieToType.FieldURIOrConstant = ciConstantType;
                iRestriction.Item = ieToType;
                findItemRequest.Restriction = iRestriction;

                FindItemResponseType findItemResponse = esb.FindItem(findItemRequest); // esb is passed in to the function

                // Get the response messages
                ResponseMessageType[] rmta = findItemResponse.ResponseMessages.Items;

                foreach (ResponseMessageType rmt in rmta)
                    FindItemResponseMessageType fiResponse = (FindItemResponseMessageType)rmt;
                    if (fiResponse.ResponseClass == ResponseClassType.Success)

    When this code executes fiResponse.ResponseClass is set to ResponseClassType.Error with a ResponseCode of "ErrorUnsupportedPathForQuery" which translates to a MessageText of "The property can not be used with this type of restriction."

    Is there a better / correct way to find a contact item by email address through the web service?

    Thank you.

    Wednesday, March 11, 2009 9:52 PM


  • The problem is with your FieldIndex = "0".  Try changing this to "EmailAddress1" and it should work.
    • Proposed as answer by Jimmy Salmon Thursday, March 12, 2009 4:06 AM
    • Marked as answer by simonventuri Thursday, March 12, 2009 11:04 AM
    Thursday, March 12, 2009 4:02 AM

All replies