Dela via


CreateItemType Class

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

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

Syntax

'Declaration
<SerializableAttribute> _
<DesignerCategoryAttribute("code")> _
<GeneratedCodeAttribute("wsdl", "2.0.50727.42")> _
<DebuggerStepThroughAttribute> _
<XmlTypeAttribute(Namespace:="https://schemas.microsoft.com/exchange/services/2006/messages")> _
Public Class CreateItemType
    Inherits BaseRequestType
[SerializableAttribute] 
[DesignerCategoryAttribute("code")] 
[GeneratedCodeAttribute("wsdl", "2.0.50727.42")] 
[DebuggerStepThroughAttribute] 
[XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages")] 
public class CreateItemType : BaseRequestType
[SerializableAttribute] 
[DesignerCategoryAttribute(L"code")] 
[GeneratedCodeAttribute(L"wsdl", L"2.0.50727.42")] 
[DebuggerStepThroughAttribute] 
[XmlTypeAttribute(Namespace=L"https://schemas.microsoft.com/exchange/services/2006/messages")] 
public ref class CreateItemType : public BaseRequestType
/** @attribute SerializableAttribute() */ 
/** @attribute DesignerCategoryAttribute("code") */ 
/** @attribute GeneratedCodeAttribute("wsdl", "2.0.50727.42") */ 
/** @attribute DebuggerStepThroughAttribute() */ 
/** @attribute XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages") */ 
public class CreateItemType extends BaseRequestType
SerializableAttribute 
DesignerCategoryAttribute("code") 
GeneratedCodeAttribute("wsdl", "2.0.50727.42") 
DebuggerStepThroughAttribute 
XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages") 
public class CreateItemType extends BaseRequestType

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.

Type

Description

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.

Inheritance Hierarchy

System.Object
   ExchangeWebServices.BaseRequestType
    ExchangeWebServices.CreateItemType

Example

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

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.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003,

Target Platforms

Windows 98, Windows 2000, Windows 2000 Server, Windows CE, Windows Longhorn, Windows 98 Second Edition, Pocket PC, Smart Phone, Windows Server 2003, Windows XP Professional with Service Pack 2 (SP2)