Independentsoft
Home
Products
Purchase
Support
Downloads
Company
Contact
PST .NET
>
Tutorial
> List all folders
The following example shows you how recursively get and list all folders.
C# example
using System; using System.Collections; using Independentsoft.Pst; namespace Sample { class Program { static void Main(string[] args) { PstFile file = new PstFile("c:\\testfolder\\Outlook.pst"); using (file) { FolderCollection folders = file.MailboxRoot.GetFolders(true); string parentFolder = file.MailboxRoot.DisplayName; Hashtable parents = new Hashtable(); parents.Add(file.MailboxRoot.Id, parentFolder); for (int i = 0; i < folders.Count; i++) { Folder currentFolder = folders[i]; parentFolder = (string)parents[currentFolder.ParentId]; string currentFolderPath = parentFolder + "\\" + currentFolder.DisplayName; parents.Add(currentFolder.Id, currentFolderPath); Console.WriteLine("Id: " + currentFolder.Id); Console.WriteLine("Name: " + currentFolder.DisplayName); Console.WriteLine("Type: " + currentFolder.ContainerClass); Console.WriteLine("Item count: " + currentFolder.ItemCount); Console.WriteLine("Path: " + currentFolderPath); Console.WriteLine("----------------------------------------------------------------"); } } Console.WriteLine("Press ENTER to exit."); Console.Read(); } } }
VB example
Imports System Imports Independentsoft.Pst Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Dim file As New PstFile("c:\testfolder\Outlook.pst") Using file Dim folders As FolderCollection = file.MailboxRoot.GetFolders(True) Dim parentFolder As String = file.MailboxRoot.DisplayName Dim parents As New Hashtable() parents.Add(file.MailboxRoot.Id, parentFolder) For i As Integer = 0 To folders.Count - 1 Dim currentFolder As Folder = folders(i) parentFolder = DirectCast(parents(currentFolder.ParentId), String) Dim currentFolderPath As String = parentFolder & "\" & currentFolder.DisplayName parents.Add(currentFolder.Id, currentFolderPath) Console.WriteLine("Id: " & currentFolder.Id) Console.WriteLine("Name: " & currentFolder.DisplayName) Console.WriteLine("Type: " & currentFolder.ContainerClass) Console.WriteLine("Item count: " & currentFolder.ItemCount) Console.WriteLine("Path: " & currentFolderPath) Console.WriteLine("----------------------------------------------------------------") Next End Using Console.WriteLine("Press ENTER to exit.") Console.Read() End Sub End Class End Namespace