Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all!

I`m using EWS Proxy Classes to create new items in ExchangeServer(emails, calendars and etc.). I ahve only one problem: i need to create item with custom CreationTime ( for example, like message was created a month ago ).
DateTimeCreate property is one of properties, that don`t have write access. But i can change them via MAPI like this:
C#
PathToExtendedFieldType q = new PathToExtendedFieldType();
        q.PropertyId = 3590; //DeliveryTime
        q.PropertyType = MapiPropertyTypeType.SystemTime;
        q.PropertyIdSpecified = true;
        newItem.ExtendedProperty[0] = new ExtendedPropertyType();
        newItem.ExtendedProperty[0].ExtendedFieldURI = q;
        newItem.ExtendedProperty[0].ExtendedFieldURI.DistinguishedPropertySetIdSpecified = true;
        newItem.ExtendedProperty[0].Item = new System.DateTime(2013, 5, 5, 5, 5, 5).ToString("yyyy-MM-ddTHH:mm:ssZ");


That code works fine. I can change SentTime and ReciveTime, but not CreationTime. I even found MAPI Property ID for DateTimeCreate, but it doesn`t works. (PR_CREATION_TIME ( PT_SYSTIME, 0x3007)).
I found resolve for C++ for MAPI creation. Resolve was: first create item, then change DateTimeCreate. I tried to create item and after UpdateItem.
C#
private void UpdateItem(ItemIdType itemID)
{
    //Update created item
    ItemIdType itemId = new ItemIdType();
    itemId.Id = itemID.Id;
    itemId.ChangeKey = itemID.ChangeKey;
    ItemType ciSetEP = new ItemType();
    //////////////////////////////////////////////////////////////////////////
    PathToExtendedFieldType extFieldURI = new PathToExtendedFieldType();
    extFieldURI.PropertyTag = Convert.ToString(ExtendedPropertyID.DateTimeCreate);
    extFieldURI.PropertyType = MapiPropertyTypeType.SystemTime;

    // Identify the custom property to set.
    ciSetEP.ExtendedProperty = new ExtendedPropertyType[1];
    ciSetEP.ExtendedProperty[0] = new ExtendedPropertyType();
    ciSetEP.ExtendedProperty[0].ExtendedFieldURI = extFieldURI;
    ciSetEP.ExtendedProperty[0].Item = DateTime.Parse("31/05/2013 01:02:03.456").ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
    // Add the calendar item and the identified custom property
    // to the ItemChangeDescriptionType. This is an SetItemFieldType.
    //////////////////////////////////////////////////////////////////////////

    SetItemFieldType setItemField = new SetItemFieldType();
    setItemField.Item = extFieldURI;
    setItemField.Item1 = ciSetEP;

    UpdateItemType request = new UpdateItemType();
    request.ItemChanges = new ItemChangeType[1] { new ItemChangeType() };
    request.ItemChanges[0].Item = itemId;
    request.ItemChanges[0].Updates = new ItemChangeDescriptionType[1];
    request.ItemChanges[0].Updates[0] = setItemField;
    request.MessageDisposition = MessageDispositionType.SaveOnly;
    request.MessageDispositionSpecified = true;

    UpdateItemResponseType updateItemResponse = m_mailbox.UpdateItem(request);
    if (updateItemResponse.ResponseMessages.Items[0].ResponseClass != ResponseClassType.Success)
        throw new EwsException(updateItemResponse.ResponseMessages.Items[0], "ESMailboxManager.UpdateItem");

}


That code works, but there is no result. I tried to update another fiedls - it works fine.

Can someone help? Really need to set that field.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900