Working with MapiTask in PST

Adding MapiTask to PST

With Aspose.Email you can add MapiTask to the Tasks subfolder of a PST file that you have created or loaded. Below are the steps to add MapiTask to a PST:

  1. Create a MapiTask object.
  2. Set the MapiTask properties using constructor and different methods.
  3. Create a PST using the PersonalStorage.Create() method.
  4. Create a pre-defined folder (Tasks) at the root of the PST file by accessing the Root folder and then calling the AddMapiMessageItem() method.

The following code snippet shows you how to create a MapiTask and then add it to the tasks folder of a newly created PST file.

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
System::String dataDir = RunExamples::GetDataDir_Outlook();
System::SharedPtr<MapiTask> task = System::MakeObject<MapiTask>(L"To Do", L"Just click and type to add new task", System::DateTime::get_Now(), System::DateTime::get_Now().AddDays(3));
task->set_PercentComplete(20);
task->set_EstimatedEffort(2000);
task->set_ActualEffort(20);
task->set_History(Aspose::Email::Outlook::MapiTaskHistory::Assigned);
task->set_LastUpdate(System::DateTime::get_Now());
task->get_Users()->set_Owner(L"Darius");
task->get_Users()->set_LastAssigner(L"Harkness");
task->get_Users()->set_LastDelegate(L"Harkness");
task->get_Users()->set_Ownership(Aspose::Email::Outlook::MapiTaskOwnership::AssignersCopy);
System::String alreadyCreated = dataDir + L"AddMapiTaskToPST_out.pst";
if (System::IO::File::Exists(alreadyCreated))
{
System::IO::File::Delete(alreadyCreated);
}
else { }
{
System::SharedPtr<PersonalStorage> personalStorage = PersonalStorage::Create(dataDir + L"AddMapiTaskToPST_out.pst", Aspose::Email::Outlook::Pst::FileFormatVersion::Unicode);
System::SharedPtr<FolderInfo> taskFolder = personalStorage->CreatePredefinedFolder(L"Tasks", Aspose::Email::Outlook::Pst::StandardIpmFolder::Tasks);
taskFolder->AddMapiMessageItem(task);
}