In Microsoft Exchange Server, emails are organized in different folders such as inbox, outbox, etc. Also, you can create your own folders or subfolders based on your needs. While working with MS Exchange Server, you may need to create custom folders programmatically. In this article, you will learn how to create folders or subfolders with EWS on MS Exchange Server in C# .NET. Also, we will cover how to delete a folder on Exchange Server.
- .NET API to Create Folders with EWS on MS Exchange Server
- Create a Folder on MS Exchange Server
- Create a Subfolder on MS Exchange Server
- Delete a Folder on MS Exchange Server
C# .NET API to Create Folders on MS Exchange Server
To manage folders with EWS on MS Exchange Server, we will utilize Aspose.Email for .NET. The API makes it quite easier to work with the Exchange Server’s services from within .NET applications. You can either download the API’s DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.Email
Create a Folder on MS Exchange Server in C#
The following are the steps to create a folder on MS Exchange Server in C#.
- Connect to MS Exchange Server and get the EWS client object in IEWSClient.
- Specify the name of the root folder and the folder you want to create.
- Create folder using IEWSClient.CreateFolder(string, string) method.
The following code sample shows how to create a folder on MS Exchange Server with EWS in C#.
Create a Subfolder on MS Exchange Server in C#
To create a subfolder, you would first need to check if the parent folder exists or not. If it does, simply create the subfolder, else create the parent folder first. The following steps demonstrate how to create a subfolder on MS Exchange Server in C#.
- Connect to MS Exchange Server and get the EWS client object in IEWSClient.
- Specify the name of the root folder and subfolder.
- Check if the parent folder exists using IEWSClient.FolderExists(string, string, ExchangeFolderInfo) method. If not, create one.
- Create subfolder using IEWSClient.CreateFolder(string, string) method.
The following code sample shows how to create a subfolder on MS Exchange Server in C#.
Delete a Folder on MS Exchange Server in C#
The following are the steps to delete a folder on MS Exchange Server in C#.
- Connect to MS Exchange Server and get the EWS client object in IEWSClient.
- Check if the folder exists using IEWSClient.FolderExists(string, string, ExchangeFolderInfo) method.
- Delete folder using IEWSClient.DeleteFolder(string, bool) method.
The following code sample shows how to delete a folder on MS Exchange Server in C#.
Get a Free API License
You can get a free temporary license to use Aspose.Email for .NET without evaluation limitations.
Conclusion
In this article, you have learned how to work with folders on Microsoft Exchange Server with EWS in C#. With the help of code samples, you have seen how to create and delete a particular folder on MS Exchange Server programmatically in C#. Besides, you can explore the documentation to read more about Aspose.Email for .NET. Also, you can ask your questions via our forum.