Aspose.Email.Examples.CSharp.Email.Exchange.CreateFoldersOnExchangeServerMailbox.Run C# (CSharp) Method

Run() public static method

public static Run ( ) : void
return void
        public static void Run()
        {
            // ExStart:CreateFoldersOnExchangeServerMailbox

            // Create instance of EWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            string inbox = client.MailboxInfo.InboxUri;
            string folderName1 = "EMAILNET-35054";
            string subFolderName0 = "2015";
            string folderName2 = folderName1 + "/" + subFolderName0;
            string folderName3 = folderName1 + " / 2015";
            ExchangeFolderInfo rootFolderInfo = null;
            ExchangeFolderInfo folderInfo = null;

            try
            {
                client.UseSlashAsFolderSeparator = true;
                client.CreateFolder(client.MailboxInfo.InboxUri, folderName1);
                client.CreateFolder(client.MailboxInfo.InboxUri, folderName2);
            }
            finally
            {
                if (client.FolderExists(inbox, folderName1, out rootFolderInfo))
                {
                    if (client.FolderExists(inbox, folderName2, out folderInfo))
                        client.DeleteFolder(folderInfo.Uri, true);
                    client.DeleteFolder(rootFolderInfo.Uri, true);
                }
            }
            // ExEnd:CreateFoldersOnExchangeServerMailbox
        }
    }
CreateFoldersOnExchangeServerMailbox