none
Trouble using EWS 2010 and trying to filter results by received date. RRS feed

  • Question

  • When I run the following responseFolder.ResponseClass = Error and the error message is "The specified value is invalid for property."
    
    Any ideas what I'm doing wrong or is this something I simply can't filter by?
    
    using (ExchangeServiceBinding esb = new ExchangeServiceBinding())
          {
            esb.Credentials = new NetworkCredential(userId, password, domain);
            esb.Url = EWSUrl;
            esb.RequestServerVersionValue = new RequestServerVersion();
            esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010;
    
            // Begin find
            FindItemType findItemType = new FindItemType();
            // Shallow to only search the specified folder.
            findItemType.Traversal = ItemQueryTraversalType.Shallow;
    
            // Setting to search the inbox only as it's a base folder and that's much easier.
            List<DistinguishedFolderIdType> folderIDs = new List<DistinguishedFolderIdType>();
            folderIDs.Add(new DistinguishedFolderIdType
            {
              Id = DistinguishedFolderIdNameType.inbox
            });
            findItemType.ParentFolderIds = folderIDs.ToArray();
    
            //// Set base fields to bring back. Can't bring everything back as each message is 
            //// limited to 512bytes. Pulling the entire message in another method.
            ItemResponseShapeType itemResponseShapeType = new ItemResponseShapeType();
            itemResponseShapeType.BaseShape = DefaultShapeNamesType.AllProperties;
            findItemType.ItemShape = itemResponseShapeType;
    
            //Greater than
            PathToUnindexedFieldType dateSentPath = new PathToUnindexedFieldType();
            dateSentPath.FieldURI = UnindexedFieldURIType.itemDateTimeSent;
            IsGreaterThanOrEqualToType isGreaterThanOrEqual = new IsGreaterThanOrEqualToType();
            isGreaterThanOrEqual.Item = dateSentPath;
            FieldURIOrConstantType dateConstraint = new FieldURIOrConstantType();
            ConstantValueType dateConstantValue = new ConstantValueType();
            dateConstantValue.Value =
              string.Format("{0}-{1}-{2}T00:00:00Z"
              , DateTime.Now.Year.ToString()
              , DateTime.Now.Month.ToString()
              , DateTime.Now.Day.ToString());
            dateConstraint.Item = dateConstantValue;
            isGreaterThanOrEqual.FieldURIOrConstant = dateConstraint;
    
            // Restriction
            RestrictionType restriction = new RestrictionType();
            restriction.Item = isGreaterThanOrEqual;
            findItemType.Restriction = restriction;
    
            // Search
            FindItemResponseType folderCollection = esb.FindItem(findItemType);
    
            // loop through folders. We only specified 1 though.
            foreach (FindItemResponseMessageType responseFolder in folderCollection.ResponseMessages.Items)
            {
              if (responseFolder.ResponseClass == ResponseClassType.Success)
              {
                // loop through message Items
                ArrayOfRealItemsType mailboxItems = (ArrayOfRealItemsType)responseFolder.RootFolder.Item;
                for (int itemCount = 0; itemCount < mailboxItems.Items.Length; itemCount++)
                {
                  ItemType inboxItem = mailboxItems.Items[itemCount];
                  ItemType email = getEmail(esb, inboxItem);
                  Console.WriteLine(email.Subject);
                  Console.WriteLine(email.DisplayTo);
                  Console.WriteLine(email.DisplayCc);
                  Console.WriteLine(email.Body.Value);
                }
    
              }
              else
              {
                Console.WriteLine(responseFolder.MessageText);
              }
            }
            Console.ReadLine();
          }
    

    Wednesday, August 24, 2011 11:10 PM

All replies

  • I don't know if .00Z is valid for the end of the tz string - all the ones I've seen have three digits there, not two.  Try changing it to .000Z .
    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    Thursday, August 25, 2011 3:25 PM