Creating Tasks in Exchange 2010

Last modified: March 16, 2009

Applies to: Exchange Server 2007 | Exchange Server 2010

You can use Exchange Web Services to create tasks in a user's mailbox.


The following example shows you how to create a weekly recurring task.

public TaskType CreateRecurringTask()
    // Create the task item and set property values.
    TaskType task = new TaskType();
    task.Subject = "This is a recurring task that was created by using the autogenerated EWS proxies.";
    task.Body = new BodyType();
    task.Body.BodyType1 = BodyTypeType.Text;
    task.Body.Value = "This task occurs every week.";
    task.StartDate = DateTime.Now;
    task.StartDateSpecified = true;

    // Create the regeneration pattern.
    WeeklyRegeneratingPatternType regenerationPattern = new WeeklyRegeneratingPatternType();
    regenerationPattern.Interval = 1;

    // Define the recurrence pattern.
    NoEndRecurrenceRangeType recurrenceRange = new NoEndRecurrenceRangeType();
    recurrenceRange.StartDate = task.StartDate;

    // Set the regeneration and recurrence patterns.
    TaskRecurrenceType recurrence = new TaskRecurrenceType();
    recurrence.Item = regenerationPattern;
    recurrence.Item1 = recurrenceRange;

    task.Recurrence = recurrence;

    // Create the request to make a new task item.
    CreateItemType createItemRequest = new CreateItemType();
    createItemRequest.Items = new NonEmptyArrayOfAllItemsType();
    createItemRequest.Items.Items = new ItemType[1];
    createItemRequest.Items.Items[0] = task;

    // Send the request and receive the response.
    CreateItemResponseType createItemResponse = this.Service.CreateItem(createItemRequest);

    // Access a response message.
    ItemInfoResponseMessageType responseMessage = createItemResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;

    // Return the new task item.
    return responseMessage.Items.Items[0] as TaskType;

public ExchangeServiceBinding Service
        if (this.service == null)
            this.service = new ExchangeServiceBinding();
            this.service.Credentials = new NetworkCredential(
            this.service.Url = this.Url;
        return this.service;

The following XML example shows the XML request message that is sent from the client to the server.

<CreateItem xmlns:xsi="" 
    <Items xmlns="">
        <Task xmlns="">
          <Subject>This is a recurring task that was created by using the autogenerated EWS proxies.</Subject>
          <Body BodyType="Text">This task occurs every week.</Body>

The following XML example shows the XML response message that is sent from the server to the client.

<CreateItemResponse xmlns:xsi="" 
  <ResponseMessages xmlns="">
    <CreateItemResponseMessage ResponseClass="Success">
        <Task xmlns="">
          <ItemId Id="AQApAHR" ChangeKey="EwAAABYA" />

The ExchangeServiceBinding object that contains the user credentials and the location of the Exchange server that has the Client Access server role installed is encapsulated in this.Service.

The SOAP messages that are passed between the Exchange Web Services client and server are defined by the XML schema and WSDL files. The XML schema and WSDL files define the contract between the client and server. Proxy class generators create an object-model abstraction of those SOAP messages, which can simplify programming. This code example uses a proxy class library that was generated by MicrosoftVisual Studio 2005. Different proxy class generators create different object models for a given Web service. This proxy class code example is an illustration only. Refer to the proxy class generator documentation for support for proxy classes.


The item identifier and change key have been shortened to preserve readability.

Compiling the Code

For information about compiling the code, see EWS Client Development in Exchange 2010.