新手需要帮助。以下代码将计算收件箱下的所有子文件夹,但问题是这些子文件夹下总是有许多文件夹。如果得到我的意思,我很难弄清楚如何计算子文件夹下的子文件夹:)
MAPIFolder oFolder = this.ns.GetSharedDefaultFolder(oRecip, OlDefaultFolders.olFolderInbox);
int result = oFolder.Folders.Count;
foreach (MAPIFolder subFolder in oFolder.Folders)
{
result =+ oFolder.Folders.Count;
}
tbFolderItemCount.Text = result.ToString();
答案 0 :(得分:2)
我不知道您正在使用的API,但您需要切换到递归方法。我认为它可能看起来像这样:
public int CountSubfolders(MAPIFolder folder)
{
int count = folder.Folders.Count;
foreach (MAPIFolder subfolder in folder.Folders)
{
count += CountSubfolders(subfolder);
}
return count;
}
你用你的根文件夹调用它:
MAPIFolder oFolder = this.ns.GetSharedDefaultFolder(oRecip, OlDefaultFolders.olFolderInbox);
int subfolders = CountSubfolders(oFolder);