The following code example demonstrates how to create a custom folder in outlook. In this example we will create a new folder with name ‘Authorcode’ in outlook, you can see in attached picture below(see circle).
you need to add reference of ‘Microsoft.Office.Interop.Outlook’ library.
The Microsoft.Office.Interop.Outlook.MAPIFolder class represents a folder that contains e-mail messages, contacts, tasks, and other items. Outlook provides 16 default MapiFolder objects. The default MapiFolder objects are defined by the Microsoft.Office.Interop.Outlook.OlDefaultFolders enumeration values. For example, OlDefaultFolders.olFolderInbox corresponds to the Inbox folder in Outlook. following code sample shows how to create a new MAPIFolder.
[VB.Net]
Private Sub CreateNewFolder() Dim oApp As Outlook.Application = New Outlook.Application Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI") Dim InboxFolder As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) Dim customFolder As Outlook.MAPIFolder Try customFolder = InboxFolder.Folders.Add("Authorcode", Outlook _ .OlDefaultFolders.olFolderInbox) InboxFolder.Folders("Authorcode").Display() Catch ex As Exception MessageBox.Show("The following error occurred: " & ex.Message) End Try End Sub
[C#.Net]
private void CreateNewFolder() { Outlook.Application oApp = new Outlook.Application(); Outlook.NameSpace oNS = oApp.GetNamespace("MAPI"); Outlook.MAPIFolder InboxFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.MAPIFolder customFolder = default(Outlook.MAPIFolder); try { customFolder = InboxFolder.Folders.Add("Authorcode", Outlook.OlDefaultFolders.olFolderInbox); InboxFolder.Folders("Authorcode").Display(); } catch (System.Exception ex) { MessageBox.Show("The following error occurred: " + ex.Message); } }