简体   繁体   English

如何计算收件箱子文件夹,包括Outlook中子文件夹下的子文件夹等

[英]How to count inbox sub-folders including sub-folders under sub-folders and so on in Outlook

Newbie in need of help. 新手需要帮助。 The following code will count all the sub-folders under the inbox but the problem is there are always a number of folders under these sub-folders. 以下代码将计算收件箱下的所有子文件夹,但问题是这些子文件夹下总是有许多文件夹。 I'm having difficulty working out how to count the sub-folders under the sub-folders if you get my meaning :) 如果你得到我的意思,我很难弄清楚如何计算子文件夹下的子文件夹:)

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();

I don't know the API you are using, but you'll need to switch over to a recursive method. 我不知道您正在使用的API,但您需要切换到递归方法。 I think it might look something like this: 我认为它可能看起来像这样:

public int CountSubfolders(MAPIFolder folder)
{
    int count = folder.Folders.Count;

    foreach (MAPIFolder subfolder in folder.Folders)
    {
        count += CountSubfolders(subfolder);
    }

    return count;
}

And you'd call it with your root folder: 你用你的根文件夹调用它:

MAPIFolder oFolder = this.ns.GetSharedDefaultFolder(oRecip, OlDefaultFolders.olFolderInbox);

int subfolders = CountSubfolders(oFolder);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复制文件夹但忽略一些子文件夹 - Copy a folder but ignoring some sub-folders NUnit测试用例生成:如何创建子文件夹(层次结构)? - NUnit testcase generation: how to create sub-folders (hierarchy)? 从 Dropbox 上的公共共享文件夹和子文件夹下载图像 - Downloading images from publicly shared folders and sub-folders on Dropbox 使用带有SharpSSH的SFTP下载文件夹和子文件夹 - Download folders and sub-folders using SFTP with SharpSSH 为C#Intellisense生成XML文件,为子文件夹损坏 - Generating XML file for C# Intellisense, broken for sub-folders 从特定结构的子文件夹中获取文件? - Get files from specifically structured sub-folders? 忽略特定子文件夹的 C# 编译警告? - Ignore C# compile warnings for specific sub-folders? 从 C# 中的文件夹和子文件夹中获取文件名 - Get file names from folder and sub-folders in C# 如何使用 EWS 托管 API 从文件夹和公共文件夹的子文件夹中获取所有项目 - How To Get all ITEMS from Folders and Sub-folders of PublicFolders Using EWS Managed API 如何将文件从文件夹和子文件夹传输到 C# 中由文件名模式创建的特定文件夹(File2specific Folders) - How to transfer files form folders and sub-folders to specific folders created by file name pattern in C# (File2specific Folders)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM