Dividir y fusionar archivos PST
La API de Aspose.Email proporciona la capacidad de dividir un solo archivo PST en múltiples archivos PST del tamaño de archivo deseado. También puede fusionar varios archivos PST en un solo archivo PST. Tanto las operaciones de dividir como de fusionar PST se pueden rastrear agregando eventos a estas operaciones.
Dividiendo en múltiples PSTs
El siguiente fragmento de código muestra cómo dividir múltiples PSTs.
// 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."); | |
} |
Dividiendo PST según un criterio especificado
El siguiente fragmento de código muestra cómo dividir PST según un criterio especificado.
// 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"); | |
} |
Fusionando en un único PST
El siguiente fragmento de código muestra cómo fusionar en un único 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."); | |
} |
¡Pruébalo!
Fusiona y combina múltiples archivos de correo electrónico en línea en uno solo con la gratuita Aplicación de Fusión de Aspose.Email.
Fusionando carpetas de otro PST
El siguiente fragmento de código muestra cómo fusionar carpetas de otro 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."); | |
} |
Métodos de ayuda
// 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++; | |
} |