获取所有 Outlook 文件夹和子文件夹的列表 [英] Get list of all Outlook folders and subfolders
问题描述
一段时间以来,我一直试图弄清楚如何获取所有 Outlook 文件夹的列表,但只能获取默认文件夹(即收件箱、发件箱、已发送邮件、已删除邮件等)的列表..)如果我创建了个人或自定义文件夹怎么办?例如,如果我向 Outlook 添加一个名为收据"的文件夹,这将不是默认文件夹,也不会显示在默认文件夹"下.我将如何在 c# 中使用 Microsoft.Office.Interop.Outlook 访问此文件夹.
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#.
我正在尝试创建一种方法来自动将某些新邮件从任何给定文件夹下载到电子表格中.我想如果我可以获得所有文件夹的列表,那么我只能从所选文件夹中获取消息.
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.olFolderInbox).Parent;
foreach (Outlook.MAPIFolder Folder in oFolders)
推荐答案
这应该会打印出 Outlook 中的所有文件夹,包括您的公用文件夹.
This should print out all the folders in your outlook including your public folders.
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);
}
}
}
这篇关于获取所有 Outlook 文件夹和子文件夹的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!