Creating Tasks for other users using Exchange Web Services (EWS) Managed API

Chris Roberts picture Chris Roberts · Jul 9, 2010 · Viewed 9.8k times · Source

As an "EWS Managed API Newbie", I'm having some problems finding examples and documentation about creating and managing Tasks.

I've managed to create a task for myself without a problem. However, I really need to be able to do the following - if anyone could give me any pointers I'd really appreciate it...

  1. Create a Task and assign it to another user.
  2. Be able to interrogate the status of that task (percent complete, etc) whilst it is assigned to that user.
  3. Update the notes on the task at any time.

Thanks in advance for any pointers!

Answer

Chip McCormick picture Chip McCormick · Feb 2, 2011

The code in this post worked for me

Pasting code for posterity:

public string CreateTaskItem(string targetMailId)
    {

        string itemId = null;

        task.Subject = "Amit: sample task created from SDE and EWS";

        task.Body = new BodyType();

        task.Body.BodyType1 = BodyTypeType.Text;

        task.Body.Value = "Amit created task for you!";

        task.StartDate = DateTime.Now;

        task.StartDateSpecified = true;



        // 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;

        /** code from create appointment **/

        DistinguishedFolderIdType defTasksFolder = new DistinguishedFolderIdType();

        defTasksFolder.Id = DistinguishedFolderIdNameType.tasks;
        defTasksFolder.Mailbox = new EmailAddressType();

        defTasksFolder.Mailbox.EmailAddress = targetMailId;

        TargetFolderIdType target = new TargetFolderIdType();

        target.Item = defTasksFolder;



        createItemRequest.SavedItemFolderId = target;


        try

        {

            // Send the request and get the response.

            CreateItemResponseType createItemResponse = _esb.CreateItem(createItemRequest);



            // Get the response messages.

            ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items;



            foreach (ResponseMessageType rmt in rmta)

            {

                ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items;

                ItemType[] items = itemArray.Items;


                // Get the item identifier and change key for each item.

                foreach (ItemType item in items)

                {


//the task id

                   Console.WriteLine("Item identifier: " + item.ItemId.Id);


//the change key for that task, would be used if you want to track changes ...
                    Console.WriteLine("Item change key: " + item.ItemId.ChangeKey);

                }

            }

        }

        catch (Exception e)

        {

            Console.WriteLine("Error Message: " + e.Message);

        }

        return itemId;

    }