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