List and modify folders on Exchange Server

GemBox.Email allows you to work with folders on the Exchange Server.

The following example shows how you can list all folders and how to create a new custom folder and then remove it.

Folders listed with GemBox.Email
Screenshot of folders listed with GemBox.Email
using System;
using GemBox.Email;
using GemBox.Email.Exchange;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create a new Exchange client.
        var exchangeClient = new ExchangeClient("<HOST> (e.g. https://outlook.office365.com/EWS/Exchange.asmx)");
        exchangeClient.Authenticate("<USERNAME>", "<PASSWORD>");

        // Create a new folder.
        exchangeClient.CreateFolder("GemBox Folder");

        // List folders on the server.
        var folders = exchangeClient.ListFolders();

        // Print folder info.
        Console.WriteLine("Folder name".PadRight(28, ' ') + " | Items | Unread items | Children folders");
        foreach (ExchangeFolderInfo folder in folders)
            Console.WriteLine(
                $"{folder.Name, -28} | " +
                $"{folder.TotalCount, -5} | " +
                $"{folder.UnreadCount, -12} | " +
                $"{folder.ChildFolderCount, -16}");

        // Delete a folder.
        exchangeClient.DeleteFolder("GemBox Folder", false);
    }
}
Imports System
Imports GemBox.Email
Imports GemBox.Email.Exchange

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        ' Create a new Exchange client.
        Dim exchangeClient = new ExchangeClient("<HOST> (e.g. https://outlook.office365.com/EWS/Exchange.asmx)")
        exchangeClient.Authenticate("<USERNAME>", "<PASSWORD>")

        ' Create a new folder.
        exchangeClient.CreateFolder("GemBox Folder")

        ' List folders on the server.
        Dim folders = exchangeClient.ListFolders()
        
        ' Print folder info.
        Console.WriteLine("Folder name".PadRight(28, " "C) + " | Items | Unread items | Children folders")
        For Each folder As ExchangeFolderInfo In folders
            Console.WriteLine(
                $"{folder.Name, -28} | " +
                $"{folder.TotalCount, -5} | " +
                $"{folder.UnreadCount, -12} | " +
                $"{folder.ChildFolderCount, -16}")
        Next

        ' Delete a folder.
        exchangeClient.DeleteFolder("GemBox Folder", false)
    End Sub
End Module

You can use the ExchangeClient.ListFolders and ExchangeClient.GetFolderInfo methods to obtain information about folders.

By using the ExchangeClient.CreateFolder, ExchangeClient.DeleteFolder, and ExchangeClient.RenameFolder methods, you can modify folders on the server.

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Email yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.