Exchange Server TechCenter > Exchange Server Forums > Development > Exchange Web Services - FindItem restriction using date/time works in US, fails in UK
Ask a questionAsk a question
 

AnswerExchange Web Services - FindItem restriction using date/time works in US, fails in UK

  • Wednesday, October 28, 2009 6:51 PMMightyMouseLDH Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hello all, hoping I can get some assistance from anyone who's encountered this issue.

    I am using EWS/VB.NET and a restriction to search for emails within a specific date range.  When the locale is set to "English (US)" the code works just fine.  When I move the application to a machine with a locale set to "English (UK)" the FindItem call fails with the error:  "Object reference not set to an instance of an object".

    I am using a DateTimePicker control, and pass the value to a variable.  Then, in my code which builds the request I convert this Date/Time value to a UTC formatted string:

                            ' Add the search criteria
    Dim StartDateReceivedField As New PathToUnindexedFieldType()
    StartDateReceivedField.FieldURI = UnindexedFieldURIType.itemDateTimeReceived

    Dim StartDateReceivedToGet As New ConstantValueType()

    StartDateReceivedToGet.Value = EndDate.ToUniversalTime().ToString()

    Again, this works flawlessly on systems set for "English (US)".  The main difference here is that in the US the format is MM/DD/YYYY, whereas in the UK it's DD/MM/YYYY.  Wouldn't the "ToUniversalTime()" .NET function convert this correctly?

    Any help here would be appreciated.

    Thank you in advance,

    Chris


Answers

  • Monday, November 02, 2009 3:33 AMDavid Claux - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    ToUniversalTime adjusts the offset to UTC of your date time, it doesn't perform any kind of formatting. Use ToString with a format string to format your DateTime the US English way.


    David Claux | Program Manager - Exchange Web Services

All Replies

  • Monday, November 02, 2009 3:33 AMDavid Claux - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    ToUniversalTime adjusts the offset to UTC of your date time, it doesn't perform any kind of formatting. Use ToString with a format string to format your DateTime the US English way.


    David Claux | Program Manager - Exchange Web Services
  • Thursday, November 05, 2009 9:17 PMMightyMouseLDH Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thank you David.  Here's an update:

    Converting the date didn't ultimately solve the problem.  Running the code works on a Windows 2008 server (with Exchange 2007 installed), but still does not work on XP.  I am continuing to try to nail down the issue and figure out exactly what it is.  The "null reference" I still believe is referring to the date format that EWS is receiving from my code.