Load personal storage PST or OST with options

GroupDocs.Conversion provides PersonalStorageLoadOptions to give you control over how the source personal storage (PST/OST) document will be processed. The following options could be set:

OptionDescription
ConvertOwned Controls whether owned documents of the document container must be converted.
ConvertOwner Controls whether the document container itself must be converted. If this property is true the document container will be the first converted document.
Depth Controls how many levels in depth to perform the conversion.
Folder  A folder to be processed. Default is Inbox.

Get folders from personal storage

The following code snippet shows how to get folders within the personal storage document:

using (Converter converter = new Converter("sample.pst"))
{
    var documentInfo = converter.GetDocumentInfo();
    var ostInfo = (PersonalStorageDocumentInfo) documentInfo;
    Console.WriteLine(ostInfo.RootFolderName);
    foreach (var folder in ostInfo.Folders)
    {
        Console.WriteLine(folder);
    }
}

Convert each personal storage content to different formats

The following code snippet shows how to convert each personal storage content to a different format based on the content type:

  • JPG attachments will be converted to PNG
  • DOCX attachments will be converted to PDF
  • Emails and all other types will be converted to HTML

With v24.10 and later:

using (Converter converter = new Converter("sample.pst", (LoadContext loadContext) =>
       {
           if (loadContext.SourceFormat == EmailFileType.Ost)
           {
               return new PersonalStorageLoadOptions
               {
                   Folder = "Inbox",
               };
           }
           if (loadContext.SourceFormat == EmailFileType.Msg)
           {
               return new EmailLoadOptions
               {
                   ConvertOwner = true,
                   ConvertOwned = true,
                   Depth = 2
               };
           }
           return null;
       }))
{
    int index = 0;
    converter.Convert((SaveContext saveContext) =>
    {
        string fileName = $"converted_{++index}.{saveContext.TargetFormat.Extension}";
        return new FileStream(fileName, FileMode.Create);
    }, (ConvertContext convertContext) =>
    {
        if (convertContext.SourceFormat == ImageFileType.Jpg)
        {
            return new ImageConvertOptions
            {
                Format = ImageFileType.Png
            };
        }
        if (convertContext.SourceFormat == WordProcessingFileType.Docx)
        {
            return new PdfConvertOptions();
        }
        return new WebConvertOptions();
    });
}

Before v24.10:

using (Converter converter = new Converter("sample.pst", (FileType fileType) =>
{
    if (fileType == EmailFileType.Ost)
    {
        return new PersonalStorageLoadOptions
        {
            Folder = "Inbox",
        };
    }
    if (fileType == EmailFileType.Msg)
    {
        return new EmailLoadOptions
        {
            ConvertOwner = true,
            ConvertOwned = true,
            Depth = 2
        };
    }
    return null;
}))
{
    int index = 0;
    converter.Convert((FileType fileType) =>
    {
        string fileName = $"converted_{++index}.{fileType.Extension}";
        return new FileStream(fileName, FileMode.Create);
    }, (string sourceFileName, FileType fileType) =>
    {
        if (fileType == ImageFileType.Jpg)
        {
            return new ImageConvertOptions
            {
                Format = ImageFileType.Png
            };
        }
        if (fileType == WordProcessingFileType.Docx)
        {
            return new PdfConvertOptions();
        }
        return new WebConvertOptions();
    });
}