ImapCreateFolder Method
Creates a new folder (mailbox in IMAP4 terms) in the IMAP4 account.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public bool CreateFolder(
	string folderName
)

Parameters

folderName
Type: SystemString
The full name of the folder to be created.

Return Value

Type: Boolean
true if the folder was created successfully; otherwise, false.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks

The developer should specify the full name of the folder (including all parent folders' names if the new folder should be a subfolder of another existing folder). For instance, imap.CreateFolder("Orders") call will create "Orders" folder, not "Inbox/Orders" even if "Inbox" folder is currently selected.

This method automatically creates parent folders if required. For instance, if folderName is "Archive/April/29" and there is no "Archive" folder in the account, this method will create "Archive", "Archive/April", and "Archive/April/29" folders.

Note Note
Although the most popular delimiter char for separating folder levels is "/", some IMAP4 servers may use "\", ".", etc, or even do not support folder hierarchy at all (flat names). The developer can obtain the folder delimiter char adopted by the current server using DownloadFolders(Boolean, String, String) method.
Note Note
Depending on the mail server implementation, folder names other than "Inbox" may be case-sensitive ("Drafts", "DRAFTS", and "drafts" may designate different folder names).

MailBee fully supports international folder names encoded with UTF-7 Modified encoding.

To create a folder asynchronously, see the sample code in BeginExecuteCustomCommand(String, String, AsyncCallback, Object) topic.

Examples
This sample connects to the IMAP4 server, logs in the mail account, and creates Orders subfolder in Inbox. If the server does not support subfolders, "Inbox/Orders" folder is created.
// To use the code below, import MailBee namespaces at the top of your code
using MailBee;
using MailBee.ImapMail;

// The actual code (put it into a method of your class)
Imap imp = new Imap();

// Connect to the server and log in the account.
imp.Connect("imap4.company.com");
imp.Login("jdoe@company.com", "secret");

// Determine what delimiter char is on the server.
FolderCollection delim = imp.DownloadFolders(false, string.Empty, string.Empty);

string folderName = null;
if (delim.Count == 0)
{
    Console.WriteLine("Bad IMAP4 server");
}
else if (delim[0].Delimiter == null)
{
    folderName = "Inbox/Orders";
    Console.WriteLine("Folder names are flat. Will create " + folderName + " folder.");
}
else
{
    folderName = "Inbox" + delim[0].Delimiter + "Orders";
    Console.WriteLine("Will create " + folderName + " folder.");
}

// Create folder
imp.CreateFolder(folderName);
Console.WriteLine(folderName + " folder successfully created.");

imp.Disconnect();
See Also