Read the complete article on how to create and delete folders with EWS on MS Exchange Server in C#: https://blog.aspose.com/2022/04/01/manage-folders-on-ms-exchange-server-in-csharp/
Last active
April 1, 2022 14:37
-
-
Save aspose-com-gists/2e3d275b59a45593fe99667e3c651e6c to your computer and use it in GitHub Desktop.
Create and Delete Folders on MS Exchange Server in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get inbox URI (to create folder in inbox) | |
string inbox = client.MailboxInfo.InboxUri; | |
// Specify folder name | |
string folderName1 = "EMAILNET-35054"; | |
try | |
{ | |
// Create folder | |
client.UseSlashAsFolderSeparator = true; | |
client.CreateFolder(client.MailboxInfo.InboxUri, folderName1); | |
} | |
catch | |
{ | |
// Do something | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get inbox URI | |
string inbox = client.MailboxInfo.InboxUri; | |
// Specify folder name | |
string folderName1 = "EMAILNET-35054"; | |
// Specify subfolder name | |
string subFolderName = "2015"; | |
string folderName2 = folderName1 + "/" + subFolderName; | |
ExchangeFolderInfo rootFolderInfo = null; | |
try | |
{ | |
client.UseSlashAsFolderSeparator = true; | |
if (!client.FolderExists(inbox, folderName1, out rootFolderInfo)) | |
{ | |
// Create folder | |
rootFolderInfo = client.CreateFolder(inbox, folderName1); | |
} | |
// Create subfolder | |
client.CreateFolder(inbox, folderName2); | |
} | |
catch | |
{ | |
// Do something | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get inbox URI | |
string inbox = client.MailboxInfo.InboxUri; | |
// Specify folder name | |
string folderName1 = "EMAILNET-35054"; | |
ExchangeFolderInfo rootFolderInfo = null; | |
try | |
{ | |
// Check if folder exists | |
if (client.FolderExists(inbox, folderName1, out rootFolderInfo)) | |
{ | |
// Delete folder | |
client.DeleteFolder(rootFolderInfo.Uri, true); | |
} | |
} | |
catch | |
{ | |
// Do something | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment