GetItemType Class

Definition

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

public ref class GetItemType : ExchangeWebServices::BaseRequestType
public class GetItemType : ExchangeWebServices.BaseRequestType
Public Class GetItemType
Inherits BaseRequestType
Inheritance
GetItemType

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");
    }
}

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.

Attachments[Ex15WebSvcsOtherRef]
Categories[Ex15WebSvcsOtherRef]
ReplyTo
Body
CcRecipients
ResponseObjects
BccRecipients
InternetMessageHeaders
ToRecipients

Constructors

GetItemType()

The GetItemType constructor initializes a new instance of the GetItemType class.

Properties

ItemIds

The ItemIds property gets or sets the collection of items to get.

ItemShape

The ItemShape property gets or sets the response shape of the GetItem response.

Applies to