How to: Create Custom Folder Items
Visual Studio 2005
| Note | Required applications |
|---|---|
|
The code example in this topic can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination. |
|
Note |
|---|
|
This code does not compile if you use the VSTO 2005 SE version of the Outlook 2003 add-in project template. For more information, see Getting Started Programming Application-Level Add-ins. |
This example creates a new folder in Microsoft Office Outlook 2003. The name of the user who is logged on is used for the folder name.
Example
private void CreateCustomFolder() { Outlook.MAPIFolder inBox = (Outlook.MAPIFolder) this.ActiveExplorer().Session.GetDefaultFolder (Outlook.OlDefaultFolders.olFolderInbox); string userName = (string)this.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); } }
Note