Adding a new folder in Outlook through C#

I guess most of us are familiar with Outlook addin’s . Add Ins make our work easier by providing some Out Of Box Features .

In this post we will be looking into how to create a new Folder in the outlook as and when our Plugin starts.

Video

Open a Outlook addin project in your Visual Studio and open the ThisAddIn class.

ThisAddIn_StartUp method will be called every time you starts the plugin or addin.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
AddMyNewFolder();

}

Inside startup method call a folder creation method.

private void AddMyNewFolder()
{

Outlook.Folder folder =Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderOutbox) as Outlook.Folder;
Outlook.Folders folders = folder.Folders;
try
{
if (folders.Count == 0)
{
Outlook.Folder newFolder = folders.Add(“Your Folder Name”, Type.Missing) as Outlook.Folder;
newFolder.Display();
}
}
catch (Exception ex)
{
MessageBox.Show(
“Could not add ‘Your Folder Name'”,”Add Folder”,
MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}

In the above method you will be seeing that first we have created a parent folder object , in this case the Outbox , and then creating a child folder.

You can set the parent folder by choosing a option from Outlook.OlDefaultFolders .

If instead of a sub folder you want to create a parent folder then in that case manipulate

Outlook.Folders folders = folder.Folders;

As

Outlook.Folders folders = folder.Parent.Folders;

Plenty of custom functionality can be achieved through addins. Will be coming up with some others.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s