Managing Tasks, Journals, and Notes in PST Files
Add MAPI Task to PST
The Creating and Managing PST Files article shows how to create a PST file and add a subfolder to it. 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:
- Create a MapiTask object.
- Set the MapiTask properties using constructor and different methods.
- Create a PST using the PersonalStorage.Create() method.
- 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/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
MapiTask task = new MapiTask("To Do", "Just click and type to add new task", DateTime.Now, DateTime.Now.AddDays(3)); | |
task.PercentComplete = 20; | |
task.EstimatedEffort = 2000; | |
task.ActualEffort = 20; | |
task.History = MapiTaskHistory.Assigned; | |
task.LastUpdate = DateTime.Now; | |
task.Users.Owner = "Darius"; | |
task.Users.LastAssigner = "Harkness"; | |
task.Users.LastDelegate = "Harkness"; | |
task.Users.Ownership = MapiTaskOwnership.AssignersCopy; | |
string alreadyCreated = dataDir + "AddMapiTaskToPST_out.pst"; | |
if (File.Exists(alreadyCreated)) | |
{ | |
File.Delete(alreadyCreated); | |
} | |
else | |
{ | |
} | |
using (PersonalStorage personalStorage = PersonalStorage.Create(dataDir + "AddMapiTaskToPST_out.pst", FileFormatVersion.Unicode)) | |
{ | |
FolderInfo taskFolder = personalStorage.CreatePredefinedFolder("Tasks", StandardIpmFolder.Tasks); | |
taskFolder.AddMapiMessageItem(task); | |
} |
Add MAPI Journal to PST
Aspose.Email also allows you to add MapiJournal to the Journal subfolder of a PST file that you have created or loaded. Below are the steps to add MapiJournal to a PST:
- Create a MapiJournal object
- Set the MapiJournal properties using a constructor and methods.
- Create a PST using the PersonalStorage.Create() method.
- Create a pre-defined folder (Journals) 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 MapiJournal and then add it to the journal folder of a newly created PST file.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
MapiJournal journal = new MapiJournal("daily record", "called out in the dark", "Phone call", "Phone call"); | |
journal.StartTime = DateTime.Now; | |
journal.EndTime = journal.StartTime.AddHours(1); | |
string path = dataDir + "CreateNewMapiJournalAndAddToSubfolder_out.pst"; | |
if (File.Exists(path)) | |
{ | |
File.Delete(path); | |
} | |
using (PersonalStorage personalStorage = PersonalStorage.Create(dataDir + "CreateNewMapiJournalAndAddToSubfolder_out.pst", FileFormatVersion.Unicode)) | |
{ | |
FolderInfo journalFolder = personalStorage.CreatePredefinedFolder("Journal", StandardIpmFolder.Journal); | |
journalFolder.AddMapiMessageItem(journal); | |
} |
Add Attachments to MAPI Journal
The following code snippet shows you how to add attachments to MapiJournal.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
string[] attachFileNames = new string[] { dataDir + "Desert.jpg", dataDir + "download.png" }; | |
MapiJournal journal = new MapiJournal("testJournal", "This is a test journal", "Phone call", "Phone call"); | |
journal.StartTime = DateTime.Now; | |
journal.EndTime = journal.StartTime.AddHours(1); | |
journal.Companies = new string[] { "company 1", "company 2", "company 3" }; | |
foreach (string attach in attachFileNames) | |
{ | |
journal.Attachments.Add(attach,File.ReadAllBytes(attach)); | |
} | |
journal.Save(dataDir + "AddAttachmentsToMapiJournal_out.msg"); |
Add MAPI Note to PST
With Aspose.Email you can add a MapiNote to the Notes subfolder of the created or loaded PST file. To add a MapiNote to a PST:
- Create a template MapiNote using Microsoft Outlook and save it as an MSG file.
- Load the saved MSG note into a MapiMessage object.
- Create a MapiNote object and load the template MSG note.
- Set the MapiNote properties.
- Create a PST using the PersonalStorage.Create() method.
- 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/aspose-email/Aspose.Email-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
MapiMessage mess = MapiMessage.FromFile(dataDir + "Note.msg"); | |
// Create three Notes | |
MapiNote note1 = (MapiNote)mess.ToMapiMessageItem(); | |
note1.Subject = "Yellow color note"; | |
note1.Body = "This is a yellow color note"; | |
MapiNote note2 = (MapiNote)mess.ToMapiMessageItem(); | |
note2.Subject = "Pink color note"; | |
note2.Body = "This is a pink color note"; | |
note2.Color = NoteColor.Pink; | |
MapiNote note3 = (MapiNote)mess.ToMapiMessageItem(); | |
note2.Subject = "Blue color note"; | |
note2.Body = "This is a blue color note"; | |
note2.Color = NoteColor.Blue; | |
note3.Height = 500; | |
note3.Width = 500; | |
string path = dataDir + "AddMapiNoteToPST_out.pst"; | |
if (File.Exists(path)) | |
{ | |
File.Delete(path); | |
} | |
using (PersonalStorage personalStorage = PersonalStorage.Create(dataDir + "AddMapiNoteToPST_out.pst", FileFormatVersion.Unicode)) | |
{ | |
FolderInfo notesFolder = personalStorage.CreatePredefinedFolder("Notes", StandardIpmFolder.Notes); | |
notesFolder.AddMapiMessageItem(note1); | |
notesFolder.AddMapiMessageItem(note2); | |
notesFolder.AddMapiMessageItem(note3); | |
} |