How to reduce the size of a PST file

Hi,

I have raised a question that PSt file size is not decreasing after deleting the messages and your response was
The structure of pst allows to delete items without decreasing the PST/OST file size. You can also verify it if you delete some messages from Outlook where even if you clean the delete itesm folder, the file size will not change. Outlook has a separate option for reducing file size, known as PST file size compacting as detailed on this page

Is there a way to reduce the size of the PST file using Aspose API?

If that is not possible then the only alternative is to create a new PST file and add all the messages from the old PST file. how to preserve the same structure/format of the old pst file in the new pst file?

My requirement is to add a custom header to all the messages in a PST file.

Is there any other alternative to do this most efficiently using Aspose email API?


Hi Satish,

Thank you for writing to us.

  1. At present, there is no method available to reduce the size of the PST file using Aspose API. We already have a new feature request logged as NETWORKNET-33398 in our issue tracking system for achieving this. However, due to other priority tasks, we may not be able to provide this feature in near future.

  2. I’m afraid but at present you will have to follow the same procedure as you have mentioned. i.e. extracting items from a source PST, adding a header to each item and then add it to a new PST. You can traverse through all the folders of the source PST and create a new PST with the same structure as shown in the following sample code. In addition, we’ll forward this requirement to our development team for inline modification of information in a PST and share with you if there can be such a feature implemented.

Sample Code:

static void PstToPST()
{
    try
    {
        Console.WriteLine("Loading OST file....");
        // load the Outlook OST file
        PersonalStorage ost = PersonalStorage.FromFile("OSTStorage.ost");
        // get the Display Name of the OST file
        Console.WriteLine("Display Name: " + ost.DisplayName);
        // get the folders and messages information
        FolderInfo folderInfo = ost.RootFolder;
        PersonalStorage NewPst = PersonalStorage.Create("Output.pst", FileFormatVersion.Unicode);
        // Add and Get the folder info
        FolderInfo NewFolderInfo = NewPst.RootFolder.AddSubFolder(folderInfo.DisplayName);
        // call the recursive method to extract msg files from each folder
        ExtractMsgFiles(folderInfo, ost, NewPst, NewFolderInfo);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

static void ExtractMsgFiles(FolderInfo folderInfo, PersonalStorage ost, PersonalStorage NewPst, FolderInfo NewFolderInfo)
{
    // display the folder name
    Console.WriteLine("Folder: " + folderInfo.DisplayName);
    Console.WriteLine("==================================");
    // loop through all the messages in this folder
    MessageInfoCollection messageInfoCollection = folderInfo.GetContents();
    foreach (MessageInfo messageInfo in messageInfoCollection)
    {
        // get the message in MapiMessage instance
        MapiMessage message = ost.ExtractMessage(messageInfo);
        try
        {
            //add new header before adding message to destination pst
            NewFolderInfo.AddMessage(message);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Folder: " + folderInfo.DisplayName);
            Console.WriteLine("Saving message {0} ....", messageInfo.Subject);
            Console.WriteLine(ex.Message);
        }
    }
    // call this method recursively for each subfolder
    if (folderInfo.HasSubFolders == true)
    {
        foreach (FolderInfo subfolderInfo in folderInfo.GetSubFolders())
        {
            FolderInfo RecNewFolderInfo = NewFolderInfo.AddSubFolder(subfolderInfo.DisplayName);
            ExtractMsgFiles(subfolderInfo, ost, NewPst, RecNewFolderInfo);
        }
    }
}

Hi Kashif,


While creating a new pst file by default it creates an empty folder “Deleted Items”. Is there any way to prevent this? I would like to replicate the exact folder structure of the source pst.
please let me know…
Also please let me know if the java email api 3.6.0 is compatible with outlook 2010?
Is the latest version 3.7.0 stable?

Hi Satish,


We are sorry for a delayed response.

The creation of “Deleted Items” in a new PST is the default structure of the PST and can’t be avoided at present. I believe this behavior replicates with respect to the PSTs created using Outlook Interop which I’m trying at my end and will share my results with you soon.

With respect to the Aspose.Email for Java 3.7.0, we had some regression issues and a hot fix version Aspose.Email for Java 3.7.1 was released afterwards. Please download this latest version at your end and use it in your applications. I would also like to share that messages and PSTs created with Aspose.Email are equally compatible with all versions of Microsoft Outlook. Please try these at your end and let us know your feedback if you face any such issue.

Hi Satish,


We have investigated this issue further at our end found that this behavior is the same as observed while creating a PST using Microsoft Interop and, hence, can’t be avoided. Please let us know if we can be of any additional help to you in this regard.

I am Outlook user. I have large numbers of PST files due to which I am facing problems while accessing data . I want to reduce PST file size . Is any possible way is there by which I can make separate folder and put all previous and older PST files there ?