How to: Programmatically 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 VSTO add-in projects for Outlook. For more information, see Features Available by Office Application and Project Type.

        private void CreateCustomFolder()
            Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
            string userName = (string)this.Application.ActiveExplorer()
            Outlook.MAPIFolder customFolder = null;
                customFolder = (Outlook.MAPIFolder)inBox.Folders.Add(userName,
                MessageBox.Show("You have created a new folder named " +
                    userName + ".");
            catch (Exception ex)
                MessageBox.Show("The following error occurred: " + ex.Message);

Working with Folders
How to: Programmatically Add an Entry to Outlook Contacts
How to: Programmatically Create Appointments