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--------------------"); }
输出:
![图片1](https://image.evget.com//Content/files/2017/8/18/cbe116b3ca2f49c989a0eb01db1151eb636386623595227624.png)
完整代码:
[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")