UpdateItemType Class

The UpdateItemType class represents a request to update a set of items.

Inheritance Hierarchy

System.Object
  ExchangeWebServices.BaseRequestType
    ExchangeWebServices.UpdateItemType

Namespace:  ExchangeWebServices
Assembly:  EWS (in EWS.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class UpdateItemType _
    Inherits BaseRequestType
'Usage
Dim instance As UpdateItemType
[SerializableAttribute]
public class UpdateItemType : BaseRequestType

Remarks

You can append, set, or delete properties when you update an item.

If you try to submit a change description that includes more than one property to modify, an ErrorIncorrectUpdatePropertyCount error will be returned.

Examples

The following code example shows you how to update a meeting. This example performs the following actions:

  1. Adds a new required attendee to the meeting.

  2. Updates the start time of the meeting to the current time on the client.

  3. Adds a custom MAPI property to the meeting.

  4. Deletes all optional attendees.

  5. Automatically resolves any conflicts in the update operation.

  6. Sends the meeting update to all attendees and saves a copy of the updated meeting request in the folder that the SavedItemFolderId property identifies.

static void UpdateItem(ExchangeServiceBinding esb)
{
    // Create calendar items to contain each non-deletion update.
    CalendarItemType ciAppendRA = new CalendarItemType();
    CalendarItemType ciSetStart = new CalendarItemType();
    CalendarItemType ciSetEP = new CalendarItemType();

    // Add a new required attendee to the calendar item.
    ciAppendRA.RequiredAttendees = new AttendeeType[1];
    ciAppendRA.RequiredAttendees[0] = new AttendeeType();
    ciAppendRA.RequiredAttendees[0].Mailbox = new EmailAddressType();
    ciAppendRA.RequiredAttendees[0].Mailbox.EmailAddress = "mskinner@example.com";
    // Identify the field to append.
    PathToUnindexedFieldType appReqAttendees = new PathToUnindexedFieldType();
    appReqAttendees.FieldURI = UnindexedFieldURIType.calendarRequiredAttendees;
    // Add the calendar item and the identified appended field to
    // the ItemChangeDescriptionType. This is an AppendToItemFieldType.
    AppendToItemFieldType append = new AppendToItemFieldType();
    append.Item = appReqAttendees;
    append.Item1 = ciAppendRA;

    // Set a new start time on a calendar item.
    ciSetStart.Start = DateTime.Now;
    ciSetStart.StartSpecified = true;
    // Identify the field to set.
    PathToUnindexedFieldType modStartTime = new PathToUnindexedFieldType();
    modStartTime.FieldURI = UnindexedFieldURIType.calendarStart;
    // Add the calendar item and the identified set field to
    // the ItemChangeDescriptionType. This is a SetItemFieldType.
    SetItemFieldType set = new SetItemFieldType();
    set.Item = modStartTime;
    set.Item1 = ciSetStart;

    // Set a custom property on a calendar item.
    PathToExtendedFieldType setMyProperty = new PathToExtendedFieldType();
    setMyProperty.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;
    setMyProperty.DistinguishedPropertySetIdSpecified = true;
    setMyProperty.PropertyName = "Milestone date";
    setMyProperty.PropertyType = MapiPropertyTypeType.String;
    // Identify the custom property to set.
    ciSetEP.ExtendedProperty = new ExtendedPropertyType[1];
    ciSetEP.ExtendedProperty[0] = new ExtendedPropertyType();
    ciSetEP.ExtendedProperty[0].ExtendedFieldURI = setMyProperty;
    ciSetEP.ExtendedProperty[0].Item = "2007-07-18";
    // Add the calendar item and the identified custom property
    // to the ItemChangeDescriptionType. This is an SetItemFieldType.
    SetItemFieldType setCustomProp = new SetItemFieldType();
    setCustomProp.Item = setMyProperty;
    setCustomProp.Item1 = ciSetEP;

    // Delete optional attendees from the calendar item.
    PathToUnindexedFieldType delOptAttendees = new PathToUnindexedFieldType();
    delOptAttendees.FieldURI = UnindexedFieldURIType.calendarOptionalAttendees;
    // Add the property to delete to the ItemChangeDescriptionType.
    DeleteItemFieldType deletion = new DeleteItemFieldType();
    deletion.Item = delOptAttendees;            

    // Create the identifier of the item to update.
    ItemIdType itemId = new ItemIdType();
    itemId.Id = "AAAlAE1BQG";
    itemId.ChangeKey = "DwAAABYAAA";

    // Create and populate the request.
    UpdateItemType request = new UpdateItemType();
    request.ItemChanges = new ItemChangeType[1] { new ItemChangeType() };
    request.ItemChanges[0].Item = itemId;
    request.ItemChanges[0].Updates = new ItemChangeDescriptionType[4];
    request.ItemChanges[0].Updates[0] = append;
    request.ItemChanges[0].Updates[1] = set;
    request.ItemChanges[0].Updates[2] = deletion;
    request.ItemChanges[0].Updates[3] = setCustomProp;

    request.ConflictResolution = ConflictResolutionType.AutoResolve;
    request.SendMeetingInvitationsOrCancellations = CalendarItemUpdateOperationType.SendToAllAndSaveCopy;
    request.SendMeetingInvitationsOrCancellationsSpecified = true;

    // Send the update request and receive the response.
    UpdateItemResponseType response = esb.UpdateItem(request);
    ArrayOfResponseMessagesType aormt = response.ResponseMessages;
    ResponseMessageType[] rmta = aormt.Items;

    foreach (ResponseMessageType rmt in rmta)
    {
        ItemInfoResponseMessageType respMsg = (rmt as ItemInfoResponseMessageType);
        foreach (ItemType item in respMsg.Items.Items)
        {
            Console.WriteLine("Item ID: " + item.ItemId.Id);
            Console.WriteLine("New change key: " + item.ItemId.ChangeKey);
            Console.ReadLine();
        }
    }
}

Note

The item identifier and change key in the request have been shortened to preserve readability.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.