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

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

图片1

完整代码: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")

慧都控件网程序

相关文章
相关标签/搜索