locked
EWS FindItem with restriction works in Exchange 2007, not in 2010 RRS feed

  • Question

  • I have an application writtten in VB.net and it works with Exchange 2007, but when run against a 2010 server fails.  Specifically, what I'm trying to do is a restriction (search) based on start date and end date.  Here is part of the code:

                  StartDateReceivedToGet.Value = EndDate.ToUniversalTime().ToString()
    
                   Debug.Print(Now() & ": Start date UTC: " & EndDate.ToUniversalTime().ToString())
    
                  Dim StartDateReceivedConstant As New FieldURIOrConstantType()
                  StartDateReceivedConstant.Item = StartDateReceivedToGet
    
                  Dim igtett As New IsGreaterThanOrEqualToType()
                  igtett.FieldURIOrConstant = StartDateReceivedConstant
                  igtett.Item = StartDateReceivedField
    
                  'restrict the returned items less than a specified date
                  Dim EndDateReceivedField As New PathToUnindexedFieldType()
                  EndDateReceivedField.FieldURI = UnindexedFieldURIType.itemDateTimeReceived
    
                  Dim EndDateReceivedToGet As New ConstantValueType()
                  EndDateReceivedToGet.Value = StartDate.ToUniversalTime().ToString()
    
                  If LogLevel > 0 Then
                    ThreadLogFile.WriteLine(Now() & ": End date UTC: " & StartDate.ToUniversalTime().ToString())
                    If LogLevel > 1 Then
                      LogFile.WriteLine(Now() & ": End date UTC: " & StartDate.ToUniversalTime().ToString())
                    End If
                  End If
    
                  Debug.Print(Now() & ": End date UTC: " & StartDate.ToUniversalTime().ToString())
    
                  Dim EndDateReceivedConstant As New FieldURIOrConstantType()
                  EndDateReceivedConstant.Item = EndDateReceivedToGet
    
                  Dim iltett As New IsLessThanOrEqualToType()
                  iltett.FieldURIOrConstant = EndDateReceivedConstant
                  iltett.Item = EndDateReceivedField
    
                  Dim at As New AndType()
                  at.Items = New SearchExpressionType(2) {}
                  at.Items(0) = igtett
                  at.Items(1) = iltett
    
                  ' Create a restriction type
                  Dim restriction As New RestrictionType()
    
                  ' Add the search expression to the restriction.
                  restriction.Item = at
    
                  ' Add the restriction criteria to the findItem request.
                  ' findItemRequest.Restriction = restriction
    
                  'Find the messages within the specified date range
    
                  Dim FIAttempts As Integer
    
                  Try
    
    FindItems:
     
                    Dim firt As FindItemResponseType = esb.FindItem(findItemRequest)
    
                    For Each firmtMessage As FindItemResponseMessageType In firt.ResponseMessages.Items
    
                      Debug.Print("Number of messages found for folder " & Folder.DisplayName & ": " & firmtMessage.RootFolder.TotalItemsInView.ToString)
    
    

    Start date value provided is 1/1/1990 6:00:00 AM

     

     

    End date value is 9/3/2010 10:21:07 PM

    So when I execute the code in against an Exchange 2007 server, it works perfectly every time.  When I execute this same code against an Exchange 2010 server, it fails.  COMMENTING OUT the restriction, running this code against the 2010 server then works.

    The exception I receive is "The specified value is invalid for the property" when trying to read firt.ResponseMessages.Items.   

    Did the date format change between versions for this FieldURI?  Any help would be appreciated.

    Thursday, September 2, 2010 10:41 PM

All replies

  • I had the same kind of problem but I've found a solution that works form me. Try to format Your date like this EndDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"). Earlier my date format was "yyyy-MM-dd HH:mm:ss" and it worked on Exchange 2007, but not 2010. Now It works on both versions.

    • Proposed as answer by Davidl74 Monday, August 8, 2011 5:09 PM
    Wednesday, October 20, 2010 9:32 AM
  • Thank you Thank you Thank you zavaz!  This fixed my issue as well and I've been searching for a LONG......... time on this one.
    Tuesday, March 29, 2011 7:35 PM
  • Thank you, this fixed my issue as well.
    Monday, August 8, 2011 5:09 PM