有许多问题询问如何在Outlook中获取文件夹,但我看到的所有答案都假设此文件夹嵌套在收件箱文件夹下。即使Microsoft's documentation也假设:
B
假设我的邮箱根目录下有以下文件夹:
private void SetCurrentFolder()
{
string folderName = "TestFolder";
//THIS STATEMENT ASSUMES WE'RE LOOKING IN THE INBOX
Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
this.Application.ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderInbox);
try
{
this.Application.ActiveExplorer().CurrentFolder = inBox.
Folders[folderName];
this.Application.ActiveExplorer().CurrentFolder.Display();
}
catch
{
MessageBox.Show("There is no folder named " + folderName +
".", "Find Folder Name");
}
}
Inbox
Drafts
如何将MyCustomFolder
(不是收件箱的子文件夹)作为MyCustomFolder
或MAPIFolder
?
答案 0 :(得分:2)
假设该文件夹是收件箱文件夹的对等方,您可以获取收件箱,然后上一层,然后检索相关文件夹:
Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
this.Application.ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.MAPIFolder rootFolder = (Outlook.MAPIFolder)inBox.Parent;
Outlook.MAPIFolder myFolder = rootFolder.Folders["MyCustomFolder"];