Independentsoft
- any library, any programming language
Home
Purchase
Support
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.Generic; using Independentsoft.Pst; namespace Sample { class Program { static void Main(string[] args) { PstFile file = new PstFile("c:\\testfolder\\Outlook.pst"); using (file) { IList
folders = file.MailboxRoot.GetFolders(true); string parentFolder = file.MailboxRoot.DisplayName; Dictionary
parents = new Dictionary
(); 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 System.Collections.Generic 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 IList(Of Folder) = file.MailboxRoot.GetFolders(True) Dim parentFolder As String = file.MailboxRoot.DisplayName Dim parents As New Dictionary(Of Long, String)() 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
Need help? Ask our developers:
Name*
Email*
Message*