プログラムによってカスタム フォルダー項目を作成する

この例では、Microsoft Office Outlook で新しいフォルダーを作成します。 ログオンしているユーザーの名前はフォルダー名に使用されます。

適用対象: このトピックの情報は、Outlook の VSTO アドイン プロジェクトに適用されます。 詳細については、「Office アプリケーションおよびプロジェクトの種類別の使用可能な機能」を参照してください。

private void CreateCustomFolder()
{
    Outlook.Folder inBox = (Outlook.Folder)
        Application.ActiveExplorer().Session.GetDefaultFolder
        (Outlook.OlDefaultFolders.olFolderInbox);
    string userName = (string)this.Application.ActiveExplorer()
        .Session.CurrentUser.Name;
    Outlook.Folder customFolder = null;
    try
    {
        customFolder = (Outlook.Folder)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);
    }
}