Partager via


GetItemType Class

The GetItemType class represents a request to get items from a mailbox in the Exchange database.

Inheritance Hierarchy

System.Object
  ExchangeWebServices.BaseRequestType
    ExchangeWebServices.GetItemType

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

Syntax

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

Remarks

The GetItem and FindItem operations provide a similar set of information. The GetItem operation is used to get items after they have been found by using FindItem, GetEvents, or SyncFolderItems operations.

GetItem returns additional properties that are not returned by FindItem. The following table shows properties not returned by FindItem but are returned by GetItem.

Examples

The following example shows you how to get two items from the Exchange database. The request uses the default response shape with the Sensitivity property returned as an additional property. The response is checked for e-mail messages and calendar items. Be aware that if the only properties that are accessed are contained in the base ItemType class, casting to the appropriate type may not be necessary.

static void GetItem(ExchangeServiceBinding esb)
{ 
    // Create the request.
    GetItemType request = new GetItemType();

    // Create the response shape.
    ItemResponseShapeType responseShape = new ItemResponseShapeType();
    responseShape.BodyType = BodyTypeResponseType.Text;
    responseShape.BodyTypeSpecified = true;
    responseShape.BaseShape = DefaultShapeNamesType.Default;
    // Add more properties to the request.
    PathToUnindexedFieldType[] sensitivity = new PathToUnindexedFieldType[1];
    sensitivity[0] = new PathToUnindexedFieldType();
    sensitivity[0].FieldURI = UnindexedFieldURIType.itemSensitivity;
    responseShape.AdditionalProperties = sensitivity;
    // Add the response shape to the request.
    request.ItemShape = responseShape;

    // Identify the items to get.
    ItemIdType[] items = new ItemIdType[2];
    items[0] = new ItemIdType();
    items[0].Id = "AAAlAE1BQG1";
    items[0].ChangeKey = "DwAAABYAAAA";
    items[1] = new ItemIdType();
    items[1].Id = "AAAlAE1BQG1";
    items[1].ChangeKey = "DwAAABYAAAA";

    // Add items to the request.
    request.ItemIds = items;

    try
    {
        // Send the request and get the response.
        GetItemResponseType resp = esb.GetItem(request);
        ArrayOfResponseMessagesType aormt = resp.ResponseMessages;
        ResponseMessageType[] rmta = aormt.Items;

        foreach (ResponseMessageType rmt in rmta)
        {
            ItemInfoResponseMessageType iirmt = (rmt as ItemInfoResponseMessageType);
            ArrayOfRealItemsType aorit = iirmt.Items;
            ItemType[] myItems = aorit.Items;
            
            // Determine the type for each item and cast to the approriate type.
            foreach (ItemType it in myItems)
            {
                // Check whether it is an e-mail.
                if (it is MessageType)
                {
                    MessageType message = (it as MessageType);
                }
                // Determine whether it is a calendar item.
                else if (it is CalendarItemType)
                {
                    CalendarItemType calendar = (it as CalendarItemType);
                }
                else 
                {
                    // Check for other item types.
                }
            }
        }
    }
    catch (Exception e)
    {
        throw new Exception("GetItem failed");
    }
}

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.