List and modify folders on Exchange Server

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

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

Screenshot of folders listed with GemBox.Email
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.

Check next example or download examples from GitHub.