Working with MapiNote in PST

Adding MapiNote to PST

With Aspose.Email you can add a MapiNote to the Notes subfolder of a PST file that you have created or loaded. To add a MapiNote to a PST:

  1. Create a template MapiNote using Microsoft Outlook and save it as an MSG file.
  2. Load the saved MSG note into a MapiMessage object.
  3. Create a MapiNote object and load the template MSG note.
  4. Set the MapiNote properties.
  5. Create a PST using the PersonalStorage.Create() method.
  6. Create a pre-defined folder (Notes) 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 MapiNote and then add it to the notes folder of a newly created PST file.

For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_Outlook();
System::SharedPtr<MapiMessage> mess = MapiMessage::FromFile(dataDir + L"Note.msg");
// Create three Notes
System::SharedPtr<MapiNote> note1 = System::DynamicCast<Aspose::Email::Outlook::MapiNote>(mess->ToMapiMessageItem());
note1->set_Subject(L"Yellow color note");
note1->set_Body(L"This is a yellow color note");
System::SharedPtr<MapiNote> note2 = System::DynamicCast<Aspose::Email::Outlook::MapiNote>(mess->ToMapiMessageItem());
note2->set_Subject(L"Pink color note");
note2->set_Body(L"This is a pink color note");
note2->set_Color(Aspose::Email::Outlook::NoteColor::Pink);
System::SharedPtr<MapiNote> note3 = System::DynamicCast<Aspose::Email::Outlook::MapiNote>(mess->ToMapiMessageItem());
note2->set_Subject(L"Blue color note");
note2->set_Body(L"This is a blue color note");
note2->set_Color(Aspose::Email::Outlook::NoteColor::Blue);
note3->set_Height(500);
note3->set_Width(500);
System::String path = dataDir + L"AddMapiNoteToPST_out.pst";
if (System::IO::File::Exists(path))
{
System::IO::File::Delete(path);
}
{
System::SharedPtr<PersonalStorage> personalStorage = PersonalStorage::Create(dataDir + L"AddMapiNoteToPST_out.pst", Aspose::Email::Outlook::Pst::FileFormatVersion::Unicode);
System::SharedPtr<FolderInfo> notesFolder = personalStorage->CreatePredefinedFolder(L"Notes", Aspose::Email::Outlook::Pst::StandardIpmFolder::Notes);
notesFolder->AddMapiMessageItem(note1);
notesFolder->AddMapiMessageItem(note2);
notesFolder->AddMapiMessageItem(note3);
}