HOWTO: EWS: Get LastModifiedTime for Items

So wondering where is LastModifiedTime?

Exchange Web Services does not seem to give you the hint when the item was last modified. This property is not available in ItemType and expected to be available only after Exchange 2007 SP1.

You can get the LastModifiedTime with the help of ExtendedProperty. I have created a sample to show you how.

public DateTime GetLastModified(string itemID)

        {

DateTime dtRet = new DateTime();

            ExchangeServiceBinding esb = new ExchangeServiceBinding();

            esb.AllowAutoRedirect = true;

            esb.Credentials = new System.Net.NetworkCredential("username", "password", "domain");

            esb.Url = "https://exchange-cas-server/ews/exchange.asmx";

            PathToExtendedFieldType[] ptufta = new PathToExtendedFieldType[1];

            ptufta[0] = new PathToExtendedFieldType();

            ptufta[0].PropertyTag = "0x3008"; //Property Tag for LastModifiedTime

            ptufta[0].PropertyType = MapiPropertyTypeType.SystemTime;

            ItemResponseShapeType irst = new ItemResponseShapeType();

            irst.BaseShape = DefaultShapeNamesType.IdOnly;

            irst.AdditionalProperties = ptufta;

            ItemIdType[] biita = new ItemIdType[1];

            biita[0] = new ItemIdType();

            biita[0].Id = itemID;

            //get the item

            GetItemType git = new GetItemType();

            git.ItemShape = irst;

            git.ItemIds = biita;

            GetItemResponseType girt = esb.GetItem(git);

            ItemType MsgItem = null;

            If (girt.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)

                MsgItem = ((ItemInfoResponseMessageType)girt.ResponseMessages.Items[0]).Items.Items[0];

           if (null != MsgItem)

DateTime.TryParse(MsgItem.ExtendedProperty[0].Item.ToString(), out dtRet);

return dtRet;

         

        }

 

Keywords: GetLastModified, GetItem, Exchange Web Services, Exchange 2007