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:
PathToExtendedFieldType q = new PathToExtendedFieldType();
q.PropertyId = 3590;
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.
private void UpdateItem(ItemIdType itemID)
{
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;
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");
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.