Empty Task Issue in Outlook

I have a problem with the following code.

//Downloading the task correctly
IList<MapiTask> tasks = ews.FetchMapiTasks(new List<string> { task_uri });
MapiTask task = tasks[0];

//Save the task correctly inside the pst file
FolderInfo pst_parentFolder = ... ;
string pstID = pst_parentFolder.AddMapiMessageItem(task);

//Correctly retrieve the task
MapiMessage mm = pstFile.ExtractMessage(pstID);

//Trying this line of code, the task is created with the last modification and reminder set to 1 January 1601
ews.CreateItem(mm);

Given your documentation, creating a task requires an object of type ExchangeTask. I have tried to write some rudimentary code that turns the MapiTask object into an ExchangeTask object, but the task created in Outlook is empty.

public static ExchangeTask ConvertTask(MapiTask task)
{
    ExchangeTaskStatus status;

    switch (task.Status)
    {
        case MapiTaskStatus.NotStarted:
            status = ExchangeTaskStatus.NotStarted;
            break;
        case MapiTaskStatus.InProgress:
            status = ExchangeTaskStatus.InProgress;
            break;
        case MapiTaskStatus.Complete:
            status = ExchangeTaskStatus.Completed;
            break;
        case MapiTaskStatus.Waiting:
            status = ExchangeTaskStatus.WaitingOnOthers;
            break;
        default: 
        case MapiTaskStatus.Deferred:
            status = ExchangeTaskStatus.Deferred;
            break;
    }

    var companies = new StringCollection();
    
    if (!task.Companies.IsNullOrEmpty())
    {
        companies.AddRange(task.Companies);
    }
    
    var exchangeTask = new ExchangeTask()
    {
        Subject = task.Subject,
        Body = task.Body,
        IsBodyHtml = (task.BodyType == BodyContentType.Html),
        
        Status = status,
        
        TotalWork = task.EstimatedEffort,
        ActualWork = task.ActualEffort,
        Mileage = task.Mileage,
        BillingInformation = task.Billing,

        Companies = companies,
        RecurrencePattern = null,
        CompletionDate = task.DateCompleted,
        UniqueUri = null
    };

    return exchangeTask;
}

Where am I going wrong?

@albertose ,
do you use 'Aspose.Email for .NET ’ product?

Yes, I do. The version is 24.2.0

I will move the post to the corresponding category.

Hello @albertose,

Could you please clarify to better understand the issue?

  • When using the CreateItem method, a task is created but its last modification date and reminder are set to January 1st, 1601?
  • And when using the CreateTask method together with your conversion method ConvertTask, an empty task is being created?

Is that correct?

Thank you.

  • Yes
  • Yes, but I solved it by setting multiple properties in my method that converts an object of type MapiTask to an ExchangeTask object, but I have a lot of problems replicating the object exactly, especially the recurrence part. But some dates are wrong, like the recurrence, reminder or expiry date
    How do I recreate in Outlook EXACTLY a task saved on a pst file?

@albertose
We have opened the following new ticket(s) in our internal issue tracking system.

Issue ID(s): EMAILNET-41415