CreateItemType Class

Definition

The CreateItemType class represents a request to create an item or response object.

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

Examples

The following code example shows a CreateItem request that creates a single e-mail, sends it to several recipients, and saves a copy of it in the Sent Items default folder.

static void CreateEmail()
{
    // Create the CreateItem request.
    CreateItemType createEmailRequest = new CreateItemType();

    // Specifiy how the e-mail will be handled.
    createEmailRequest.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
    createEmailRequest.MessageDispositionSpecified = true;

    // Specify the location of sent items.
    createEmailRequest.SavedItemFolderId = new TargetFolderIdType();
    DistinguishedFolderIdType sentitems = new DistinguishedFolderIdType();
    sentitems.Id = DistinguishedFolderIdNameType.sentitems;
    createEmailRequest.SavedItemFolderId.Item = sentitems;

    // Create the array of items.
    createEmailRequest.Items = new NonEmptyArrayOfAllItemsType();

    // Create a single e-mail message.
    MessageType message = new MessageType();
    message.Subject = "Daily Report";
    message.Body = new BodyType();
    message.Body.BodyType1 = BodyTypeType.Text;
    message.Body.Value = "(1) Handled customer issues, (2) Saved the world.";
    message.ItemClass = "IPM.Note";
    message.Sender = new SingleRecipientType();
    message.Sender.Item = new EmailAddressType();
    message.Sender.Item.EmailAddress = "user1@example.com";
    message.ToRecipients = new EmailAddressType[1];
    message.ToRecipients[0] = new EmailAddressType();
    message.ToRecipients[0].EmailAddress = "user2@example.com";
    message.Sensitivity = SensitivityChoicesType.Normal;
    message.SensitivitySpecified = true;
    message.Importance = ImportanceChoicesType.High;
    message.ImportanceSpecified = true;

    // Add the message to the array of items to be created.
    createEmailRequest.Items.Items = new ItemType[1];
    createEmailRequest.Items.Items[0] = message;

    try
    {
        // Create the service binding.
        // Identify the service and the user.
        ExchangeServiceBinding esb = new ExchangeServiceBinding();
        esb.Credentials = new NetworkCredential("username", "password", "domain");
        esb.Url = @"https://ExchangeServer.com/EWS/Exchange.asmx";

        // Send a CreateItem request and get the CreateItem response.
        CreateItemResponseType createItemResponse = esb.CreateItem(createEmailRequest);
        ArrayOfResponseMessagesType responseMessages = createItemResponse.ResponseMessages;

        // Access the response message.
        ResponseMessageType responseMessage = responseMessages.Items[0];
        // Determine whether the request was a success.
        if (responseMessages.Items[0].ResponseClass == ResponseClassType.Error)
        {
            throw new Exception(responseMessages.Items[0].MessageText);
        }
        if (responseMessage is ItemInfoResponseMessageType)
        {
            ItemInfoResponseMessageType createItemResp = (responseMessage as ItemInfoResponseMessageType);
            ArrayOfRealItemsType aorit = createItemResp.Items;

            // Determine whether there are items in response.
            if (aorit.Items != null)
            {
                foreach (ItemType item in aorit.Items)
                {
                    if (item is ItemType)
                    {
                        ItemType myItem = (item as ItemType);
                    }
                    if (item is MessageType)
                    {
                        MessageType myMessage = (item as MessageType);
                    }
                    // TODO: Add logic to check and cast for all other types.
                }
            }
        }
        else
        {
            Console.WriteLine("Item(s) created");
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

Remarks

The CreateItemType is used to create response objects and items in the Exchange database. The following table describes the items and response objects that can be created by using CreateItemType.

ItemType Represents a generic item to be created in the Exchange database.
MessageType Represents an e-mail message to be created in the Exchange database.
TaskType Represents a task to be created in the Exchange database.
ContactItemType Represents a contact item to be created in the Exchange database.
CalendarItemType Represents a calendar entry to be created in the Exchange database.
AcceptItemType Represents a response object for accepting meeting invitations.
CancelCalendarItemType Represents a response object for canceling a calendar item.
DeclineItemType Represents a response object for declining meeting invitations.
ForwardItemType Represents a response object for forwarding an item to other users.
RemoveItemType Represents a response object for removing a canceled meeting from a calendar.
ReplyAllToItemType Represents a response object for replying to all recipients of an item.
ReplyToItemType Represents a response object for replying to the sender of an item.
TentativelyAcceptItemType Represents a response object for tentatively accepting a meeting invitation.
SuppressReadReceiptType Represents a response object that is used to suppress read receipts.

Note: CreateItemType cannot be used to create distribution lists, meeting messages, meeting request messages, meeting response messages, and meeting cancellation messages.

Constructors

CreateItemType()

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

Properties

Items

The Items property gets or sets the collection of items to create.

MessageDisposition

The MessageDisposition property gets or sets an enumeration that describes how an item is handled after it is created. This property is required for e-mail messages.

MessageDispositionSpecified

The MessageDispositionSpecified property gets or sets a Boolean value that specifies whether the MessageDisposition property is serialized into the Simple Object Access Protocol (SOAP) request.

SavedItemFolderId

The SavedItemFolderId property gets or sets the folder in which new items are saved.

SendMeetingInvitations

The SendMeetingInvitations property gets or sets an enumeration that describes how meeting requests are handled after they are created. This property is required for calendar items.

SendMeetingInvitationsSpecified

The SendMeetingInvitationsSpecified property gets or sets a Boolean value that specifies whether the SendMeetingInvitations is serialized into the Simple Object Access Protocol (SOAP) request.

Applies to