Разделение и объединение файлов PST
Aspose.Email API предоставляет возможность разделить один файл PST на несколько файлов PST желаемого размера. Он также может объединять несколько файлов PST в один файл PST. Операции разделения и объединения PST могут быть отслежены путем добавления событий к этим операциям.
Разделение на несколько PST
Следующий фрагмент кода показывает, как разделить несколько PST.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
try | |
{ | |
String dstSplit = dataDir + Convert.ToString("Chunks\\"); | |
// Delete the files if already present | |
foreach (string file__1 in Directory.GetFiles(dstSplit)) | |
{ | |
File.Delete(file__1); | |
} | |
using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "Sub.pst")) | |
{ | |
// The events subscription is an optional step for the tracking process only. | |
personalStorage.StorageProcessed += PstSplit_OnStorageProcessed; | |
personalStorage.ItemMoved += PstSplit_OnItemMoved; | |
// Splits into pst chunks with the size of 5mb | |
personalStorage.SplitInto(5000000, dataDir + @"\Chunks\"); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose Email License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); | |
} |
Разделение PST на основе заданного критерия
Следующий фрагмент кода показывает, как разделить PST на основе заданного критерия.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
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"); | |
} |
Объединение в один PST
Следующий фрагмент кода показывает, как объединить в один PST.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
string dst = dataDir + "Sub.pst"; | |
totalAdded = 0; | |
try | |
{ | |
using (PersonalStorage personalStorage = PersonalStorage.FromFile(dst)) | |
{ | |
// The events subscription is an optional step for the tracking process only. | |
personalStorage.StorageProcessed += PstMerge_OnStorageProcessed; | |
personalStorage.ItemMoved += PstMerge_OnItemMoved; | |
// Merges with the pst files that are located in separate folder. | |
personalStorage.MergeWith(Directory.GetFiles(dataDir + @"MergePST\")); | |
Console.WriteLine("Total messages added: {0}", totalAdded); | |
} | |
Console.WriteLine(Environment.NewLine + "PST merged successfully at " + dst); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose Email License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); | |
} |
Попробуйте это!
Объедините и комбинируйте несколько файлов электронной почты онлайн в один с помощью бесплатного Aspose.Email Merger App.
Объединение папок из другого PST
Следующий фрагмент кода показывает, как объединить папки из другого PST.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
try | |
{ | |
using (PersonalStorage destinationPst = PersonalStorage.FromFile(dataDir + @"destination.pst")) | |
using (PersonalStorage sourcePst = PersonalStorage.FromFile(dataDir + @"source.pst")) | |
{ | |
FolderInfo destinationFolder = destinationPst.RootFolder.AddSubFolder("FolderFromAnotherPst"); | |
FolderInfo sourceFolder = sourcePst.GetPredefinedFolder(StandardIpmFolder.DeletedItems); | |
// The events subscription is an optional step for the tracking process only. | |
destinationFolder.ItemMoved += destinationFolder_ItemMoved; | |
// Merges with the folder from another pst. | |
destinationFolder.MergeWith(sourceFolder); | |
Console.WriteLine("Total messages added: {0}", totalAdded); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose Email License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); | |
} |
Вспомогательные методы
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
static void PstMerge_OnStorageProcessed(object sender, StorageProcessedEventArgs e) | |
{ | |
Console.WriteLine("*** The storage is merging: {0}", e.FileName); | |
} | |
static void PstMerge_OnItemMoved(object sender, ItemMovedEventArgs e) | |
{ | |
if (currentFolder == null) | |
{ | |
currentFolder = e.DestinationFolder.RetrieveFullPath(); | |
} | |
string folderPath = e.DestinationFolder.RetrieveFullPath(); | |
if (currentFolder != folderPath) | |
{ | |
Console.WriteLine(" Added {0} messages to \"{1}\"", messageCount, currentFolder); | |
messageCount = 0; | |
currentFolder = folderPath; | |
} | |
messageCount++; | |
totalAdded++; | |
} |
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
static void destinationFolder_ItemMoved(object sender, ItemMovedEventArgs e) | |
{ | |
totalAdded++; | |
} |