DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Motivations for Creating Filter and Merge Plugins for Apache JMeter With Use Cases
  • Introducing the MERGE Command in PostgreSQL 15
  • Improve Efficiency With Smaller Code Reviews
  • Techniques You Should Know as a Kafka Streams Developer

Trending

  • The Ultimate Guide to Code Formatting: Prettier vs ESLint vs Biome
  • Proactive Security in Distributed Systems: A Developer’s Approach
  • How to Format Articles for DZone
  • Building a Real-Time Change Data Capture Pipeline With Debezium, Kafka, and PostgreSQL
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. How to Split Single PST File into Multiple PSTs & Merge Multiple PSTs using .NET

How to Split Single PST File into Multiple PSTs & Merge Multiple PSTs using .NET

By 
David Zondray user avatar
David Zondray
·
Jun. 24, 15 · Code Snippet
Likes (0)
Comment
Save
Tweet
Share
1.5K Views

Join the DZone community and get the full member experience.

Join For Free
This technical tip explains how to .NET developers can split and Merge PST files using Aspose.Email.  Aspose.Email API provides the capability to split a single PST file into multiple PST files of desired file size. It can also merge multiple PST files into a single PST file. Both the splitting and merging of PSTs operations can be tracked by adding events to these operations.  Aspose.Email for .NET is a set of components allowing developers to easily implement email functionality within their ASP.NET web applications, web services & Windows applications. It Supports Outlook PST, EML, MSG & MHT formats.
//Code sample for Splitting a Single PST into multiple PSTs

 [C#]

using (PersonalStorage pst = PersonalStorage.FromFile(@"D:\test\source.pst"))
{
    // The events subscription is an optional step for the tracking process only.
    pst.StorageProcessed += PstSplit_OnStorageProcessed;
    pst.ItemMoved += PstSplit_OnItemMoved;

    // Splits into pst chunks with the size of 5mb
    pst.SplitInto(5000000, @"D:\test\chunks\");
}

 
[VB.NET]

Using pst As PersonalStorage = PersonalStorage.FromFile("D:\test\source.pst")
	' The events subscription is an optional step for the tracking process only.
	pst.StorageProcessed += PstSplit_OnStorageProcessed
	pst.ItemMoved += PstSplit_OnItemMoved

	' Splits into pst chunks with the size of 5mb
	pst.SplitInto(5000000, "D:\test\chunks\")


//Code sample for Merging of Multiple PSTs into a single PST
 
[C#]

totalAdded = 0;

using (PersonalStorage pst = PersonalStorage.FromFile(@"D:\test\destination.pst"))
{
    // The events subscription is an optional step for the tracking process only.
    pst.StorageProcessed += PstMerge_OnStorageProcessed;
    pst.ItemMoved += PstMerge_OnItemMoved;

    // Merges with the pst files that are located in separate folder.
    pst.MergeWith(Directory.GetFiles(@"D:\test\sources\"));
    Console.WriteLine("Total messages added: {0}", totalAdded);
}

[VB.NET]

totalAdded = 0

Using pst As PersonalStorage = PersonalStorage.FromFile("D:\test\destination.pst")
	' The events subscription is an optional step for the tracking process only.
	pst.StorageProcessed += PstMerge_OnStorageProcessed
	pst.ItemMoved += PstMerge_OnItemMoved

	' Merges with the pst files that are located in separate folder.
	pst.MergeWith(Directory.GetFiles("D:\test\sources\"))
	Console.WriteLine("Total messages added: {0}", totalAdded)
End Using

//Code sample Merging Folders from another PST

[C#]

totalAdded = 0;

using (PersonalStorage destinationPst = PersonalStorage.FromFile(@"D:\test\destination.pst"))
using (PersonalStorage sourcePst = PersonalStorage.FromFile(@"D:\test\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);
}

[VB.NET]

totalAdded = 0

Using destinationPst As PersonalStorage = PersonalStorage.FromFile("D:\test\destination.pst")
	Using sourcePst As PersonalStorage = PersonalStorage.FromFile("D:\test\source.pst")
		Dim destinationFolder As FolderInfo = destinationPst.RootFolder.AddSubFolder("FolderFromAnotherPst")t
		Dim sourceFolder As FolderInfo = 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)
	End Using
End Using
//Helping Methods
void destinationFolder_ItemMoved(object sender, ItemMovedEventArgs e)
    {
        totalAdded++;
    }

    void PstMerge_OnStorageProcessed(object sender, StorageProcessedEventArgs e)
    {
        Console.WriteLine("*** The storage is merging: {0}", e.FileName);
    }

    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++;
    }

    void PstSplit_OnStorageProcessed(object sender, StorageProcessedEventArgs e)
    {
        if (currentFolder != null)
        {
            Console.WriteLine("    Added {0} messages to \"{1}\"", messageCount, currentFolder);
        }

        messageCount = 0;
        currentFolder = null;
        Console.WriteLine("*** The chunk is processed: {0}", e.FileName);
    }

    void PstSplit_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++;
    } 

Merge (version control)

Opinions expressed by DZone contributors are their own.

Related

  • Motivations for Creating Filter and Merge Plugins for Apache JMeter With Use Cases
  • Introducing the MERGE Command in PostgreSQL 15
  • Improve Efficiency With Smaller Code Reviews
  • Techniques You Should Know as a Kafka Streams Developer

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!