我正在寻找“收件箱”主文件夹中子文件夹的唯一ID。
现在,我可以使应用程序吐出Outlook中用户的“根收件箱”中的所有文件夹,但是我需要“收件箱”文件夹中子文件夹的唯一ID。
我尝试使用深度遍历,并查看了其他StackOverflow答案,但均未成功。
class Program
{
static void Main(string[] args)
{
ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
Service.UseDefaultCredentials = false;
Service.Credentials = new WebCredentials("xxxx", "xxxx");
Mailbox ProdSupportMailbox = new Mailbox("xxxx");
Service.AutodiscoverUrl("xxxx");
FolderView view = new FolderView(100);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
view.PropertySet.Add(FolderSchema.DisplayName);
view.Traversal = FolderTraversal.Deep;
FindFoldersResults findFolderResults = Service.FindFolders(WellKnownFolderName.Root,
new FolderView(int.MaxValue) { Traversal = FolderTraversal.Deep});
// FindFoldersResults findFolderResults = Service.FindFolders(WellKnownFolderName.Root, view);
// Find specific folder
foreach(Folder f in findFolderResults.Folders)
{
Console.WriteLine(f.DisplayName);
/*
if (f.DisplayName == "Inbox")
Console.WriteLine(f.Id);
*/
}
}
}
理想情况下,如果我知道子文件夹的名称,那么只要我能说出是否(f.DisplayName ==“ Inbox / Subfolder”),那将很容易。 Console.WriteLine(f.Id);