获取所有Outlook文件夹和子文件夹的列表 [英] Get list of all Outlook folders and subfolders
问题描述
一段时间以来,我一直在试图找出所有Outlook文件夹的列表,但只能获取默认文件夹的列表(即收件箱,发件箱,已发送邮件,已删除邮件等). ).如果我已创建个人或自定义文件夹怎么办?例如,如果我将一个名为"Receipts"的文件夹添加到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屋!