Search code examples
c#exchange-serverexchangewebservicesexchange-server-2010

How to get the millisecond part of the DateTimeRecieved field of emailmessage using EWS managed APIs


I have a code which synchronizes with exchange and gets the emailmessage objects for the given itemids:

List<EmailMessage> emails = new List<EmailMessage>();
            ServiceResponseCollection<GetItemResponse> response =
                            MyExchangeService.BindToItems(MyItemIds, PropertySet);
            foreach (GetItemResponse getItemResponse in response)
            {
                if (getItemResponse.Item != null)
                {
                    emails.Add((EmailMessage)getItemResponse.Item);
                }
            }

Now, the emailmessage object that I get as a result, contains the DateTimeReceived property as 9/15/2017 5:27:16 AM whereas I would like it to contain the millisecond part of the time as well. Is it possible?


Solution

  • You need to set the precision on the ExchangeService class see https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.datetimeprecision(v=exchg.80).aspx to millisecond before you make the call