tags:

views:

953

answers:

4

I'm trying to use Exchange Web Services to update a calendar item. I'm creating an ItemChangeType, and then an ItemIdType. I have a unique ID to use for ItemIdType.Id, but I have nothing to use for the ChangeKey. When I leave it out, I get an ErrorChangeKeyRequiredForWriteOperations. But when i try to just put something in there, I get an ErrorInvalidChangeKey.

What can I use for this to get it to work?

I'm also trying to determine what is the best implementation of BaseItemIdType to use for ItemChangeType.Item. So far, I'm using ItemIdType, and I'm guessing that's correct, but I haven't been able to find any particularly helpful documentation on this.

+1  A: 

If you have the ItemIdType.Id property you should also have access to the Changekey, it's also a property of ItemIdType:

ItemIdType.ChangeKey

Like the Id property it's a string, so you can grab it when you grab the Id.

Regards Jesper Hauge

Hauge
+2  A: 

To be a bit more explicit on Hauge's answer: the ChangeKey is stored in Exchange and identifies the current state of the item. Any change to that item creates a new ChangeKey.

This allows Exchange to "know" that your update is being applied to the same item state as when you looked at the item - it hasn't changed since you checked it.

Some code available at: http://msdn.microsoft.com/en-us/library/aa563020.aspx

jeffreypriebe
A: 

If you know ID only, you can get ChangeKey easily, for example for folder:

  private FolderIdType GetFullFolderID(string folderID)
  {
     GetFolderType request = new GetFolderType();
     request.FolderIds = new BaseFolderIdType[1];

     FolderIdType id = new FolderIdType();
     id.Id = folderID;
     request.FolderIds[0] = id;

     request.FolderShape = new FolderResponseShapeType();
     request.FolderShape.BaseShape = DefaultShapeNamesType.IdOnly;

     GetFolderResponseType response = _binding.GetFolder(request);

     FailOnError(response);

     FolderInfoResponseMessageType firmt = (FolderInfoResponseMessageType)response.ResponseMessages.Items[0];
     FolderType ft = (FolderType)firmt.Folders[0];
     id.ChangeKey = ft.FolderId.ChangeKey;

     return id;
  }
aloneguid
A: 

thank you for your answer! it was what I was looking for!

serbgius