共用方式為


HOW TO:建立自訂資料夾項目

更新:2007 年 11 月

適用於

本主題中的資訊僅適用於指定的 Visual Studio Tools for Office 專案和 Microsoft Office 版本。

專案類型

  • 應用程式層級專案

Microsoft Office 版本

  • Outlook 2003

  • Outlook 2007

如需詳細資訊,請參閱依應用程式和專案類型提供的功能

這個範例會在 Microsoft Office Outlook 中建立新的資料夾。會使用登入使用者的名稱做為資料夾名稱。

範例

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)
        MessageBox.Show("You have created a new folder named " _
            & userName & ".")
        inBox.Folders(userName).Display()
    Catch ex As Exception
        MessageBox.Show("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);
    }
}

請參閱

工作

HOW TO:將項目加入至 Outlook 連絡人

HOW TO:建立約會

概念

使用資料夾