如何:以编程方式按名称检索文件夹
此示例获取对已命名自定义文件夹的引用,然后显示该文件夹的内容。
**适用于:**本主题中的信息适用于 Outlook 2013 和 Outlook 2010 的应用程序级项目。有关更多信息,请参见按 Office 应用程序和项目类型提供的功能。
示例
Private Sub SetCurrentFolder()
Dim folderName As String = "TestFolder"
Dim inBox As Outlook.MAPIFolder = Me.Application.ActiveExplorer().Session. _
GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Try
Me.Application.ActiveExplorer().CurrentFolder = inBox.Folders(folderName)
Me.Application.ActiveExplorer().CurrentFolder.Display()
Catch
MsgBox("There is no folder named " & folderName & _
".", "Find Folder Name")
End Try
End Sub
private void SetCurrentFolder()
{
string folderName = "TestFolder";
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");
}
}
编译代码
此示例需要:
- 取名为 TestFolder 的文件夹。