PST文件用於存儲與Outlook和Exchange程序中保存的電子郵件文件夾、地址、聯繫信息、電子郵件消息和其餘數據相關的信息。 Spire.Email支持讀取PST文件並獲取文件夾信息,如文件夾名稱,消息計數和未讀消息計數。this
Step 1:將PST文件從磁盤加載到OutlookFile類的實例中。blog
OutlookFile olf = new OutlookFile(@"C:\Users\jack\Documents\Outlook Files\Sample.pst");
Step 2:獲取文件夾集合。圖片
OutlookFolderCollection folderCollection = olf.RootOutlookFolder.GetSubFolders();
Step 3:遍歷集合並獲取集合中每一個元素的文件夾信息。get
foreach (OutlookFolder folder in folderCollection) { Console.WriteLine("Folder: " + folder.Name); Console.WriteLine("Total items: " + folder.ItemCount); Console.WriteLine("Total unread items: " + folder.UnreadItemCount); Console.WriteLine("Whether this folder has subfolders: {0}", (folder.HasSubFolders)?"Yes":"No"); Console.WriteLine("------------------Next Folder--------------------"); }
輸出:it
完整代碼:io
[C#]foreach
OutlookFile olf = new OutlookFile(@"C:\Users\jack\Documents\Outlook Files\Sample.pst"); OutlookFolderCollection folderCollection = olf.RootOutlookFolder.GetSubFolders(); foreach (OutlookFolder folder in folderCollection) { Console.WriteLine("Folder: " + folder.Name); Console.WriteLine("Total items: " + folder.ItemCount); Console.WriteLine("Total unread items: " + folder.UnreadItemCount); Console.WriteLine("Whether this folder has subfolders: {0}", (folder.HasSubFolders)?"Yes":"No"); Console.WriteLine("------------------Next Folder--------------------"); } Console.WriteLine("Completed");
[VB.NET]遍歷
Dim olf As New OutlookFile("C:\Users\jack\Documents\Outlook Files\Sample.pst") Dim folderCollection As OutlookFolderCollection = olf.RootOutlookFolder.GetSubFolders() For Each folder As OutlookFolder In folderCollection Console.WriteLine("Folder: " + folder.Name) Console.WriteLine("Total items: " + folder.ItemCount) Console.WriteLine("Total unread items: " + folder.UnreadItemCount) Console.WriteLine("Whether this folder has subfolders: {0}", If((folder.HasSubFolders), "Yes", "No")) Console.WriteLine("------------------Next Folder--------------------") Next Console.WriteLine("Completed")
慧都控件網程序