Question

I've been working on a project to allow people to access their Outlook tasks online via a web browser and be able to mark these tasks as "Complete" without the need to go into Outlook to do this. This has been achieved using EWS in C#.

However there is a funny bug where if you mark a task as "Complete" via the web application and if you go into Outlook and try to update the status of that task (e.g. mark it as still in progress), the task still displays as being striked out.

If you mark a task as complete directly from Outlook, the strikethrough will be displayed for that task in the list and if you "uncomplete" it then the strikethrough will disappear. This is NOT happening for tasks being marked as complete from the web app.

This is my code that I use to mark a task as complete:

 protected override bool ActionTask(ActionArgs data)
    {
        ConnectToServer();


        //Create Identifier of task item to update
        var itemId = new ItemIdType
        {
            Id = data.Id,
            ChangeKey = GetChangeKey(data.Id)    //Need to grab task's change key
        };

        //Create task item to hold a set update
        var setStatusTask = new TaskType
        {
            Status = TaskStatusType.Completed,
            StatusSpecified = true
        };

        //Create set update
        var setItemField = new SetItemFieldType
        {
            Item = new PathToUnindexedFieldType(),
            Item1 = setStatusTask
        };

        (setItemField.Item as PathToUnindexedFieldType).FieldURI = UnindexedFieldURIType.taskStatus;

        //Create the update request.
        UpdateItemType updateItemRequest = new UpdateItemType();
        updateItemRequest.ItemChanges = new ItemChangeType[1];

        var itemChange = new ItemChangeType()
        {
            Item = itemId,
            Updates = new ItemChangeDescriptionType[1]
        };

        itemChange.Updates[0] = setItemField;
        updateItemRequest.ItemChanges[0] = itemChange;

        UpdateItemResponseType updateItemResponse = ExchangeServiceBinding.UpdateItem(updateItemRequest);

        if (updateItemResponse.ResponseMessages.Items.Length > 0)
            return (updateItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success);

        return false;
    }

I cannot for the life of me figure out if there's something missing in my code or if this is simply just a strange Outlook bug.

Thanks heaps. :)

Was it helpful?

Solution

It looks like you're using the generated proxies to do your work, and your coding would be simplified by using the EWS Managed API (EWSMA). To mark a task as complete in EWSMA, just use the following code.

        // Bind to the existing task by using the ItemId.
        // This method call results in a GetItem call to EWS.
        Task task = Task.Bind(service, itemId);

        // Update the Status of the task.
        task.Status = TaskStatus.Completed;

        // Save the updated task.
        // This method call results in an UpdateItem call to EWS.
        task.Update(ConflictResolutionMode.AlwaysOverwrite);

Then to uncomplete it, change the following line.

       task.Status = TaskStatus.NotStarted;

I've run this and checked the output in Outlook. The first chunk of code marks the task and complete with strikethrough in Outlook, and the second removes the strikethrough and the complete checkmark.

For more information about using EWSMA, see Get started with EWS Managed API client applications.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top