Export (0) Print
Expand All

How to: Create Custom Folder Items

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.

Applies to: The information in this topic applies to application-level projects for Outlook 2007 and Outlook 2010. For more information, see Features Available by Office Application and Project Type.


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


Community Additions

ADD
Show:
© 2014 Microsoft