查找使用EWS收件箱文件夹的所有子文件夹 [英] Find all subfolders of the Inbox folder using EWS

查看:973
本文介绍了查找使用EWS收件箱文件夹的所有子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的收件箱文件夹结构:

I have the following Inbox folder structure:

Inbox
--ABC
----ABC 2
----ABC 3
--XYZ
----XYZ 2
--123
----123 A
----123 B
----123 C

我使用外汇Web服务和下面的代码找到收件箱文件夹的子文件夹:

I am using Exchange Web Services and the following code to find the child folders of the Inbox folder:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

service.AutodiscoverUrl("MyName@MyDomain.com");
Mailbox mb = new Mailbox("MyName@MyDomain.com");

FindFoldersResults findResults = service.FindFolders(
    WellKnownFolderName.Inbox,
    new FolderView(int.MaxValue));

foreach (Folder folder in findResults.Folders)
{
    Console.WriteLine(folder.DisplayName);
}

这部分工作,因为它返回的ABC,XYZ,和123文件夹;不幸的是,它不会返回内的每个这些文件夹的文件夹(ABC 2,ABC 3,XYZ 2,123 A,123 B,123 C)。

This partly works because it returns the ABC, XYZ, and 123 folders; unfortunately, it does not return the folders inside each of those folders (ABC 2, ABC 3, XYZ 2, 123 A, 123 B, 123 C).

此外,它可能是一个文件夹可以有它里面的子文件夹的多个级别。

Also, it is possible that a folder could have more than one level of subfolders inside it.

我怎么可以这样写代码,以便将返回所有子文件夹,无论有多深嵌套他们可能是?

How can I write this code so that it will return all subfolders regardless of how deeply nested they may be?

推荐答案

您可以告诉EWS搜索文件夹时做深跨度。您可以使用 FolderView.Traversal 财产。然后,您的代码将改为类似下面的内容:

You can tell EWS to do a deep traversal when searching the folders. You can do this using the FolderView.Traversal property. Your code would then be changed to something similar to the following:

FindFoldersResults findResults = service.FindFolders(
    WellKnownFolderName.Inbox,
    new FolderView(int.MaxValue) { Traversal = FolderTraversal.Deep });

这篇关于查找使用EWS收件箱文件夹的所有子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆