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?