如何:以编程方式创建自定义文件夹项

此示例在 Microsoft Office Outlook 中创建一个新文件夹。将使用已登录用户的名称作为文件夹名。

**适用于:**本主题中的信息适用于 Outlook 2013 和 Outlook 2010 的应用程序级项目。有关更多信息,请参见按 Office 应用程序和项目类型提供的功能

示例

Private Sub CreateNewFolder()
    Dim inBox As Outlook.MAPIFolder = Me.Application.ActiveExplorer().Session. _
        GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    Dim userName As String = Me.Application.ActiveExplorer() _
        .Session.CurrentUser.Name
    Dim customFolder As Outlook.MAPIFolder
    Try
        customFolder = inBox.Folders.Add(userName, Outlook _
           .OlDefaultFolders.olFolderInbox)
        MsgBox("You have created a new folder named " _
            & userName & ".")
        inBox.Folders(userName).Display()
    Catch ex As Exception
        MsgBox("The following error occurred: " & ex.Message)
    End Try
End Sub
private void CreateCustomFolder()
{
    Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
        this.Application.ActiveExplorer().Session.GetDefaultFolder
        (Outlook.OlDefaultFolders.olFolderInbox);
    string userName = (string)this.Application.ActiveExplorer()
        .Session.CurrentUser.Name;
    Outlook.MAPIFolder customFolder = null;
    try
    {
        customFolder = (Outlook.MAPIFolder)inBox.Folders.Add(userName,
            Outlook.OlDefaultFolders.olFolderInbox);
        MessageBox.Show("You have created a new folder named " +
            userName + ".");
        inBox.Folders[userName].Display();
    }
    catch (Exception ex)
    {
        MessageBox.Show("The following error occurred: " + ex.Message);
    }
}

请参见

任务

如何:以编程方式向 Outlook 联系人添加项

如何:以编程方式创建约会

概念

使用文件夹