How to do FindItem using Extended MAPI Properties in a Exchange Web Service call?

We can perform GetItem Exchange Web Service call to get Extended MAPI Properties refer my previous post How to get Extended MAPI Properties in the GetItem Exchange Web Service call? and can also perform FindItem based on the Extended MAPI Properties.

In the sample code given below we would use CleanGlobalObjectId to perform FindItem for Calendar Items:

NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures.


    private void SelectRecordByCGOID()
            //prepare the find item request: we have to use FindItem because
            //this is the only way to search by CleanGlobalObjectID; GetItem does not allow us
            //to search with Restrictions
            FindItemType findItemRequest = new FindItemType();
            DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
            folderIDArray[0] = new DistinguishedFolderIdType();
            folderIDArray[0].Id = DistinguishedFolderIdNameType.calendar;
            folderIDArray[0].Mailbox = new EmailAddressType();
            folderIDArray[0].Mailbox.EmailAddress = "";
            // Add folders to the request.
            findItemRequest.ParentFolderIds = folderIDArray;
            findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
            //Prepare an Item shape type that defines how the items in view will be returned.
            ItemResponseShapeType itemShapeDefinition = new ItemResponseShapeType();
            itemShapeDefinition.BaseShape = DefaultShapeNamesType.AllProperties  ;
            //filter the results by the CleanGlobalObjectID passed in
            PathToExtendedFieldType path = new PathToExtendedFieldType();
            path.PropertyId = 35;
            path.PropertyIdSpecified = true;
            path.PropertySetId = "6ED8DA90-450B-101B-98DA-00AA003F1305";
            path.PropertyType = MapiPropertyTypeType.Binary;
            FieldURIOrConstantType constant = new FieldURIOrConstantType();
            ConstantValueType constantValue = new ConstantValueType();
            constantValue.Value = itemGCOID ;
            constant.Item = constantValue;
            RestrictionType restriction = new RestrictionType();
            IsEqualToType equal = new IsEqualToType();
            equal.Item = path;
            equal.FieldURIOrConstant = constant;
            restriction.Item = equal;
            //Add the itemShape definition and restriction to the FindItem request
            findItemRequest.ItemShape = itemShapeDefinition;
            findItemRequest.Restriction = restriction;
            FindItemResponseType findItemResponse = binding.FindItem(findItemRequest);
            for (int i = 0; i < findItemResponse.ResponseMessages.Items.Length; i++)
                //verify the FindItem request was successfull
                if (findItemResponse.ResponseMessages.Items[i].ResponseClass != ResponseClassType.Success)
                    throw new Exception(string.Format(
                        "Unable to find calendar view by CleanGlobalObjectID \r\n{0}\r\n{1}",
                        //get the calendar items contained in the response
                        FindItemResponseMessageType findItemResponseMessage = (FindItemResponseMessageType)findItemResponse.ResponseMessages.Items[i];
                        ArrayOfRealItemsType findItemResponseItems = (ArrayOfRealItemsType)findItemResponseMessage.RootFolder.Item;
                        for (int x = 0; x < findItemResponseMessage.RootFolder.TotalItemsInView; x++)
                            if (findItemResponseItems.Items[x] is CalendarItemType)
                                CalendarItemType calendar = (CalendarItemType)findItemResponseItems.Items[x];
                                Console.WriteLine( "Item found ");
                                Console.WriteLine( calendar.Subject);

Hope this helps!

Comments (1)

  1. Anonymous says:


    Thanks for the example but I have one question.

    What object does the "FindItem" method exist on. You have an object called "binding" what is this and where did it come from?