Поделиться через


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

Comments

  • Anonymous
    June 19, 2008
    PingBack from http://demetrius.toplovestories.com/16ews.html

  • Anonymous
    March 09, 2009
    Omg ... what a horrable variable names! Looks like some kind of weird language! Not readable at all!

  • Anonymous
    August 04, 2009
    OK. Now my question is how to get the mail "FROM" item?

  • Anonymous
    August 05, 2009
    @Erik - Sorry to make it difficult for you to read. One recommendation... switch to managed API :) @Ada - Cast it to whatever type of Item it is... MessageType or CalendarType and read the From property I was casting it to base ItemType to keep it simple. Reference: http://msdn.microsoft.com/en-us/library/exchangewebservices.messagetype.aspx look at the members of the MessageType