Exchange 2007 - Web Services - MoveItem No Longer Returns ID
-
Tuesday, January 23, 2007 1:06 PM
Have moved an ASP.NET application which accesses an Exchange 2007 mailbox via EWS from the Beta2 release of Exchange 2007 to the 120 day trial (which is based on [or is] the RTM version I assume?).
Previously, using the MoveItem method returned the ID of the moved email (ID and ChangeKey). In this latest version that is no longer the case - the move is successful but nothing is returned. Online documentaion on MSDN (http://msdn2.microsoft.com/en-us/library/aa565781.aspx) shows a remark
"Remarks
This operation does not return the identifiers for the items that were moved."Important question - what is the best way of finding the new ID of the moved email? (answered by following advise in post mentioned below)
Not so important question - why did this change from B2, where MoveItem returned the ID? I am storing an abbreviated form of the email in my own database and need to store the ID to enable Reply / ReplyAll and Forward.
I have seen this post (http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=1075190&SiteID=17) which will probably give me the answer I need for sending and then moving emails, but I also need to move incoming emails to an 'actioned' folder once they have been processed and I am unsure how I can add a custom attribute / field to an existing email. (also answered by reading the forum!) I'm just wondering why the change from the Beta which worked very well and did return IDs. (this is the only part I'm still wondering about).
Thanks,
John
All Replies
-
Tuesday, January 23, 2007 3:39 PM
Actually I am struggling a little here. If anyone has an example of how to append an extended field to an existing email sitting in the inbox then that would be great.
Thanks,
John -
Tuesday, January 23, 2007 6:00 PM
The reason that we removed the Ids from both MoveItem and CopyItem responses was that obtaining the Ids required an explicit search in the destination directory for each moved item. When moving or copying a lot of item, perf went down considerably. Certainly, there are situations where you need the new ids for the items, but there are also items when you do not. As such, we decided to remove the "tax" from the equation and if consumers want to get the new ids, they can find them themselves.
To do this, you essentially do what we had in the code during beta. Before moving the item, grab the PR_SEARCHKEY via GetItem and then after the move, do a FindItem and restrict on that search key.
-
Tuesday, January 23, 2007 6:26 PM
Just grab the Id of the message in the inbox and then call this method... You will also need to create your own extended prop (Example below)
public static ItemIdType AppendExtendedProp(ExchangeServiceBinding binding,
ExtendedPropertyType extendedProperty,
ItemIdType id)
{
UpdateItemType request = new UpdateItemType();
request.ConflictResolution = ConflictResolutionType.AlwaysOverwrite;
request.MessageDisposition = MessageDispositionType.SaveOnly;
request.MessageDispositionSpecified = true;
ItemType updatedItem = new ItemType();
updatedItem.ExtendedProperty = new ExtendedPropertyType[]{extendedProperty};
SetItemFieldType setItem = new SetItemFieldType();
setItem.Item = extendedProperty.ExtendedFieldURI;
setItem.Item1 = updatedItem;
ItemChangeType itemChange = new ItemChangeType();
itemChange.Item = id;
itemChange.Updates = new ItemChangeDescriptionType[] { setItem };
request.ItemChanges = new ItemChangeType[] { itemChange };
UpdateItemResponseType response = binding.UpdateItem(request);
ItemInfoResponseMessageType responseMessage = response.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
if (responseMessage.ResponseCode != ResponseCodeType.NoError)
{
//Explode();
}
return responseMessage.Items.Items[0].ItemId;
}
And here is an example of calling it...
ExtendedPropertyType
ep = new ExtendedPropertyType(); PathToExtendedFieldType epPath = new PathToExtendedFieldType();epPath.PropertySetId =
Guid.NewGuid().ToString("D"); // just create a namespace for our custom propepPath.PropertyName =
"Fuzzy Blue Property"; // creative property nameepPath.PropertyType =
MapiPropertyTypeType.String;ep.ExtendedFieldURI = epPath;
ep.Item =
"Blue123"; // property value// Note that Id is the Id of the item in the inbox
AppendExtendedProp(binding, ep, id);
-
Wednesday, January 24, 2007 2:08 PM
Thanks David, I've now got the app running back as it was under Beta2, with the added benefit of the delay no longer being an issue.
May sound like a strange request, but if the reason that you removed the return of IDs was due to performance issues when working with large numbers of items, it would be nice to have 2 methods for each operation - MoveItem and MoveItemReturningID perhaps. This might make EWS much larger, but would significantly reduce the complexity of my code. I'm dreading the day I need to come back and bugfix my app!
Many thanks again for your responsiveness,
John -
Wednesday, January 24, 2007 4:25 PMThat isn't a strange request. I entered it for consideration (this has come up before). Rather than having a separate method, it would make more sense to add an attribute to the method called ReturnIds (bool) that will return the Ids if true. As it stands, both MoveItem and CopyItem return ItemInfoResponseMessageType instances, so no changes would be necessary there. We will see what the powers that be say about it.

