DeleteItemType Class

The DeleteItemType class represents a request to delete items in an Exchange database.

Inheritance Hierarchy

System.Object
  ExchangeWebServices.BaseRequestType
    ExchangeWebServices.DeleteItemType

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

Syntax

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

Remarks

The DeleteItemType class is used to delete items from a user's mailbox. The RemoveItem response object on a meeting cancellation notice should be used to remove canceled meetings from a user's mailbox.

The order of the items that is specified by the ItemIds property determines the order of the response messages that are returned in the response. This means that the second item that is identified to be deleted will correspond to the second response message. One response message is created for each item that is to be deleted.

Examples

The following code example shows you how to delete two items. The deleted items are moved to the Deleted Items folder. If the item is a task, only the specified task is deleted. If the item is a meeting, a meeting cancellation is sent to all the attendees.

static void DeleteItem(ExchangeServiceBinding esb)
{ 
    // Create the request.
    DeleteItemType request = new DeleteItemType();

    // Identify the items to delete.
    ItemIdType[] items = new ItemIdType[2];
    items[0] = new ItemIdType();
    items[0].Id = "AAAlAE1BQG1";
    items[1] = new ItemIdType();
    items[1].Id = "AAAlAE1BQG2";
    request.ItemIds = items;

    // Identify how deleted items are handled.
    request.DeleteType = DisposalType.MoveToDeletedItems;

    // Identify how tasks are deleted.
    request.AffectedTaskOccurrences = AffectedTaskOccurrencesType.SpecifiedOccurrenceOnly;
    request.AffectedTaskOccurrencesSpecified = true;

    // Identify how meeting cancellations are handled.
    request.SendMeetingCancellations = CalendarItemCreateOrDeleteOperationType.SendOnlyToAll;
    request.SendMeetingCancellationsSpecified = true;

    try
    {
        // Send the response and receive the request.
        DeleteItemResponseType response = esb.DeleteItem(request);
        ArrayOfResponseMessagesType aormt = response.ResponseMessages;
        ResponseMessageType[] rmta = aormt.Items;

        // Check each response message.
        foreach (ResponseMessageType rmt in rmta)
        {
            if (rmt.ResponseClass == ResponseClassType.Success)
            {
                Console.WriteLine("Deleted item.");
            }
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

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.