原創|使用教程|編輯:王香|2017-08-18 14:20:10.000|閱讀 536 次
概述:Spire.Email 是一個專業且獨立使用的.NET 電子郵件庫,本文介紹了如何從C#,VB.NET中的PST文件獲取文件夾信息。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
PST文件用于存儲與Outlook和Exchange程序中保存的電子郵件文件夾、地址、聯系信息、電子郵件消息和其他數據相關的信息。 Spire.Email支持讀取PST文件并獲取文件夾信息,如文件夾名稱,消息計數和未讀消息計數。
Step 1:將PST文件從磁盤加載到OutlookFile類的實例中。
OutlookFile olf = new OutlookFile(@"C:\Users\jack\Documents\Outlook Files\Sample.pst");
Step 2:獲取文件夾集合。
OutlookFolderCollection folderCollection = olf.RootOutlookFolder.GetSubFolders();
Step 3:遍歷集合并獲取集合中每個元素的文件夾信息。
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--------------------"); }
輸出:
完整代碼:
[C#]
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")
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn