您的位置:首页 > 编程语言 > VB

Spire.Email 教程:从C#,VB.NET中的PST文件获取文件夹信息

2017-08-18 00:00 615 查看
摘要: Spire.Email 是一个专业且独立使用的.NET 电子邮件库,本文介绍了如何从C#,VB.NET中的PST文件获取文件夹信息。

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")

慧都控件网
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息