C# 获取所有 Outlook 文件夹和子文件夹的列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10423989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get list of all Outlook folders and subfolders
提问by mtlca401
I have been trying to figure out how to get a list of all outlook folders for quite some time now, but can only get a list of the default folders (i.e. Inbox, outbox, sent items, deleted items, etc...). What if I have personal or custom folders that I have created? For instance, if I add a folder to outlook called "Receipts", this would not be a default folder and would not show up under the "default folders". How would I access this folder using Microsoft.Office.Interop.Outlook in c#.
一段时间以来,我一直试图弄清楚如何获取所有 Outlook 文件夹的列表,但只能获取默认文件夹的列表(即收件箱、发件箱、已发送邮件、已删除邮件等)。如果我创建了个人或自定义文件夹怎么办?例如,如果我向 Outlook 添加一个名为“收据”的文件夹,这将不是默认文件夹,也不会显示在“默认文件夹”下。我将如何在 c# 中使用 Microsoft.Office.Interop.Outlook 访问此文件夹。
I am trying to create a way to automatically download certain new messages into a spreadsheet from any given folder. I figured if I can get a list of all folders then I can only get the messages from the chosen folders.
我正在尝试创建一种方法来自动将某些新邮件从任何给定文件夹下载到电子表格中。我想如果我可以获得所有文件夹的列表,那么我只能从所选文件夹中获取消息。
Outlook._Folders oFolders;
Outlook.MAPIFolder oPublicFolder = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolder??Inbox).Parent;
foreach (Outlook.MAPIFolder Folder in oFolders)
采纳答案by BrainPicker
This should print out all the folders in your outlook including your public folders.
这应该打印出 Outlook 中的所有文件夹,包括您的公用文件夹。
foreach (MAPIFolder folder in olNS.Folders)
{
GetFolders(folder);
}
public void GetFolders(MAPIFolder folder)
{
if (folder.Folders.Count == 0)
{
Console.WriteLine(folder.FullFolderPath);
}
else
{
foreach (MAPIFolder subFolder in folder.Folders)
{
GetFolders(subFolder);
}
}
}
回答by Michael Kremser
See on MSDN "How to: Enumerate Folders": http://msdn.microsoft.com/en-us/library/ff184607.aspx
请参阅 MSDN“如何:枚举文件夹”:http: //msdn.microsoft.com/en-us/library/ff184607.aspx

