Udostępnij za pośrednictwem


How to: Create Custom Folder Items

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Application-level projects

Microsoft Office version

  • Outlook 2003

  • Outlook 2007

For more information, see Features Available by Application and Project Type.

This example creates a new folder in Microsoft Office Outlook. The name of the user who is logged on is used for the folder name.

Example

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);
    }
}

See Also

Tasks

How to: Add an Entry to Outlook Contacts

How to: Create Appointments

Concepts

Working with Folders