public static void Run() { // ExStart:UpdateBulkMessagesInPSTFile // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook() + "Sub.pst"; // Load the Outlook PST file PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir); // Get Requierd Subfolder FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox"); // find messages having From = "*****@*****.**" PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder(); queryBuilder.From.Contains("*****@*****.**"); // Get Contents from Query MessageInfoCollection messages = inbox.GetContents(queryBuilder.GetQuery()); // Save (MessageInfo,EntryIdString) in List IList<string> changeList = new List<string>(); foreach (MessageInfo messageInfo in messages) { changeList.Add(messageInfo.EntryIdString); } // Compose the new properties MapiPropertyCollection updatedProperties = new MapiPropertyCollection(); updatedProperties.Add(MapiPropertyTag.PR_SUBJECT_W, new MapiProperty(MapiPropertyTag.PR_SUBJECT_W, Encoding.Unicode.GetBytes("New Subject"))); updatedProperties.Add(MapiPropertyTag.PR_IMPORTANCE, new MapiProperty(MapiPropertyTag.PR_IMPORTANCE, BitConverter.GetBytes((long)2))); // update messages having From = "*****@*****.**" with new properties inbox.ChangeMessages(changeList, updatedProperties); }
public static void Run() { // ExStart:DeleteBulkItemsFromPSTFile // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook() + @"Sub.pst"; using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir)) { // Get Inbox SubFolder from Outlook file FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox"); // Create instance of PersonalStorageQueryBuilder PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder(); queryBuilder.From.Contains("*****@*****.**"); MessageInfoCollection messages = inbox.GetContents(queryBuilder.GetQuery()); IList <string> deleteList = new List <string>(); foreach (MessageInfo messageInfo in messages) { deleteList.Add(messageInfo.EntryIdString); } // delete messages having From = "*****@*****.**" inbox.DeleteChildItems(deleteList); } // ExEnd:DeleteBulkItemsFromPSTFile }
public static void Run() { // ExStart:DeleteBulkItemsFromPSTFile // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook() + @"Sub.pst"; using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir)) { // Get Inbox SubFolder from Outlook file FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox"); // Create instance of PersonalStorageQueryBuilder PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder(); queryBuilder.From.Contains("*****@*****.**"); MessageInfoCollection messages = inbox.GetContents(queryBuilder.GetQuery()); IList<string> deleteList = new List<string>(); foreach (MessageInfo messageInfo in messages) { deleteList.Add(messageInfo.EntryIdString); } // delete messages having From = "*****@*****.**" inbox.DeleteChildItems(deleteList); } // ExEnd:DeleteBulkItemsFromPSTFile }
public static void Run() { // The path to the File directory. // ExStart:SearchStringInPSTWithIgnoreCaseParameter string dataDir = RunExamples.GetDataDir_Outlook(); string path = dataDir + "SearchStringInPSTWithIgnoreCaseParameter_out.pst"; if (File.Exists(path)) { File.Delete(path); } using (PersonalStorage personalStorage = PersonalStorage.Create(dataDir + "SearchStringInPSTWithIgnoreCaseParameter_out.pst", FileFormatVersion.Unicode)) { FolderInfo folderInfo = personalStorage.CreatePredefinedFolder("Inbox", StandardIpmFolder.Inbox); folderInfo.AddMessage(MapiMessage.FromMailMessage(MailMessage.Load(dataDir + "Message.eml"))); PersonalStorageQueryBuilder builder = new PersonalStorageQueryBuilder(); // IgnoreCase is True builder.From.Contains("automated", true); MailQuery query = builder.GetQuery(); MessageInfoCollection coll = folderInfo.GetContents(query); Console.WriteLine(coll.Count); } // ExEnd:SearchStringInPSTWithIgnoreCaseParameter }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); // ExStart:1 using (PersonalStorage pst = PersonalStorage.FromFile(dataDir + "Outlook.pst")) { PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder(); queryBuilder.OnlyFoldersCreatedByUser.Equals(true); FolderInfoCollection subfolders = pst.RootFolder.GetSubFolders(queryBuilder.GetQuery()); foreach (FolderInfo folder in subfolders) { Console.WriteLine(folder.DisplayName); } } // ExEnd:1 }
public static void Run() { // The path to the File directory. // ExStart:SpecificCriterionSplitPST string dataDir = RunExamples.GetDataDir_Outlook(); IList <MailQuery> criteria = new List <MailQuery>(); PersonalStorageQueryBuilder pstQueryBuilder = new PersonalStorageQueryBuilder(); pstQueryBuilder.SentDate.Since(new DateTime(2005, 04, 01)); pstQueryBuilder.SentDate.Before(new DateTime(2005, 04, 07)); criteria.Add(pstQueryBuilder.GetQuery()); pstQueryBuilder = new PersonalStorageQueryBuilder(); pstQueryBuilder.SentDate.Since(new DateTime(2005, 04, 07)); pstQueryBuilder.SentDate.Before(new DateTime(2005, 04, 13)); criteria.Add(pstQueryBuilder.GetQuery()); using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "PersonalStorage_New.pst")) { personalStorage.SplitInto(criteria, dataDir + "pathToPst"); } // ExEnd:SpecificCriterionSplitPST }
public static void Run() { // The path to the File directory. // ExStart:SpecificCriterionSplitPST string dataDir = RunExamples.GetDataDir_Outlook(); IList <MailQuery> criteria = new List <MailQuery>(); PersonalStorageQueryBuilder pstQueryBuilder = new PersonalStorageQueryBuilder(); pstQueryBuilder.SentDate.Since(new DateTime(2005, 04, 01)); pstQueryBuilder.SentDate.Before(new DateTime(2005, 04, 07)); criteria.Add(pstQueryBuilder.GetQuery()); pstQueryBuilder = new PersonalStorageQueryBuilder(); pstQueryBuilder.SentDate.Since(new DateTime(2005, 04, 07)); pstQueryBuilder.SentDate.Before(new DateTime(2005, 04, 13)); criteria.Add(pstQueryBuilder.GetQuery()); if (Directory.GetFiles(dataDir + "pathToPst", "*.pst").Length == 0) { } else { string[] files = Directory.GetFiles(dataDir + "pathToPst"); foreach (string file in files) { if (file.Contains(".pst")) { File.Delete(file); } } } using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "PersonalStorage_New.pst")) { personalStorage.SplitInto(criteria, dataDir + "pathToPst"); } // ExEnd:SpecificCriterionSplitPST }
public static void Run() { // ExStart:UpdateBulkMessagesInPSTFile // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook() + "Sub.pst"; // Load the Outlook PST file PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir); // Get Requierd Subfolder FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox"); // find messages having From = "*****@*****.**" PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder(); queryBuilder.From.Contains("*****@*****.**"); // Get Contents from Query MessageInfoCollection messages = inbox.GetContents(queryBuilder.GetQuery()); // Save (MessageInfo,EntryIdString) in List IList <string> changeList = new List <string>(); foreach (MessageInfo messageInfo in messages) { changeList.Add(messageInfo.EntryIdString); } // Compose the new properties MapiPropertyCollection updatedProperties = new MapiPropertyCollection(); updatedProperties.Add(MapiPropertyTag.PR_SUBJECT_W, new MapiProperty(MapiPropertyTag.PR_SUBJECT_W, Encoding.Unicode.GetBytes("New Subject"))); updatedProperties.Add(MapiPropertyTag.PR_IMPORTANCE, new MapiProperty(MapiPropertyTag.PR_IMPORTANCE, BitConverter.GetBytes((long)2))); // update messages having From = "*****@*****.**" with new properties inbox.ChangeMessages(changeList, updatedProperties); // ExEnd:UpdateBulkMessagesInPSTFile }
public static void Run() { // The path to the File directory. // ExStart:SpecificCriterionSplitPST string dataDir = RunExamples.GetDataDir_Outlook(); IList<MailQuery> criteria = new List<MailQuery>(); PersonalStorageQueryBuilder pstQueryBuilder = new PersonalStorageQueryBuilder(); pstQueryBuilder.SentDate.Since(new DateTime(2005, 04, 01)); pstQueryBuilder.SentDate.Before(new DateTime(2005, 04, 07)); criteria.Add(pstQueryBuilder.GetQuery()); pstQueryBuilder = new PersonalStorageQueryBuilder(); pstQueryBuilder.SentDate.Since(new DateTime(2005, 04, 07)); pstQueryBuilder.SentDate.Before(new DateTime(2005, 04, 13)); criteria.Add(pstQueryBuilder.GetQuery()); if (Directory.GetFiles(dataDir + "pathToPst", "*.pst").Length == 0) { } else { string[] files = Directory.GetFiles(dataDir + "pathToPst"); foreach (string file in files) { if(file.Contains(".pst")) File.Delete(file); } } using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "PersonalStorage_New.pst")) { personalStorage.SplitInto(criteria, dataDir + "pathToPst"); } // ExEnd:SpecificCriterionSplitPST }
public static void Run() { // ExStart:SearchMessagesAndFoldersInPST // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "Outlook.pst")) { FolderInfo folder = personalStorage.RootFolder.GetSubFolder("Inbox"); PersonalStorageQueryBuilder builder = new PersonalStorageQueryBuilder(); // High importance messages builder.Importance.Equals((int)MapiImportance.High); MessageInfoCollection messages = folder.GetContents(builder.GetQuery()); Console.WriteLine("Messages with High Imp:" + messages.Count); builder = new PersonalStorageQueryBuilder(); builder.MessageClass.Equals("IPM.Note"); messages = folder.GetContents(builder.GetQuery()); Console.WriteLine("Messages with IPM.Note:" + messages.Count); builder = new PersonalStorageQueryBuilder(); // Messages with attachments AND high importance builder.Importance.Equals((int)MapiImportance.High); builder.HasFlags(MapiMessageFlags.MSGFLAG_HASATTACH); messages = folder.GetContents(builder.GetQuery()); Console.WriteLine("Messages with atts: " + messages.Count); builder = new PersonalStorageQueryBuilder(); // Messages with size > 15 KB builder.MessageSize.Greater(15000); messages = folder.GetContents(builder.GetQuery()); Console.WriteLine("messags size > 15Kb:" + messages.Count); builder = new PersonalStorageQueryBuilder(); // Unread messages builder.HasNoFlags(MapiMessageFlags.MSGFLAG_READ); messages = folder.GetContents(builder.GetQuery()); Console.WriteLine("Unread:" + messages.Count); builder = new PersonalStorageQueryBuilder(); // Unread messages with attachments builder.HasNoFlags(MapiMessageFlags.MSGFLAG_READ); builder.HasFlags(MapiMessageFlags.MSGFLAG_HASATTACH); messages = folder.GetContents(builder.GetQuery()); Console.WriteLine("Unread msgs with atts: " + messages.Count); // Folder with name of 'SubInbox' builder = new PersonalStorageQueryBuilder(); builder.FolderName.Equals("SubInbox"); FolderInfoCollection folders = folder.GetSubFolders(builder.GetQuery()); Console.WriteLine("Folder having subfolder: " + folders.Count); builder = new PersonalStorageQueryBuilder(); // Folders with subfolders builder.HasSubfolders(); folders = folder.GetSubFolders(builder.GetQuery()); Console.WriteLine(folders.Count); } // ExEnd:SearchMessagesAndFoldersInPST }