Binding to an Item with UniqueId and ChangeKey using EWS Managed API
-
Saturday, January 26, 2013 8:27 PM
I was recently surprised to see that 2 emails in the same Exchange folder had exactly same ItemId.UniqueId (using EWS Managed API).
I did some research and found this:
http://stackoverflow.com/a/13093036Although it appeared strange, I assimilated the fact that its not UniqueId but UniqueId+ChangeKey that would be unique for Exchange items. Now the above post already shows how to set ChangeKey using reflection to bind to a particular item in a set that share the same UniqueId.
But I would rather like to know why EWS Managed API decided to keep ChangeKey setter internal, when in fact it might happen that there were 2 emails in a folder sharing same UniqueId, user chose to delete 1 of them but a EWS api call from my code ended up deleting the other as EWS API did not give me an option to specify which ChangeKey to bind to (there must be some reason obviously the SDK team decided to keep it internal even when it can lead to binding to unintended item).
I always think tomorrow will have more time than today. And every today seems to pass-by faster than yesterday.
Rahul Singla | http://www.rahulsingla.com
All Replies
-
Monday, January 28, 2013 6:02 AM
ItemId's are unique (if they weren't it would create major issues within EWS) generally people whom observe them not being unqiue is because of whats noted on http://msdn.microsoft.com/en-us/library/aa580234.aspx "Identifies a specific item in the Exchange store. Id is case-sensitive; therefore, comparisons between Ids must be case-sensitive or binary.", So usually it caused by preforming a Case insensitive match (or storing them in a Case Insenstive format). (Or they are looking at recurring Items) .
The ChangeKey indicates the version of a particular Item which is import if your using UpdateItem. This is a good read http://blogs.msdn.com/b/pcreehan/archive/2009/07/08/deleteitem-ignores-changekeys.aspx
I can only guess why they didn't include an overload for setting the ChangeKey in the Managed API is that they expect people would always first bind to the Item and call update.
Cheers
Glen- Marked As Answer by Rahul Singla Monday, January 28, 2013 7:37 PM

