Rebex Graph
.NET client library for MS Graph API (Exchange Online)
Download 30-day free trial Buy from $199More .NET libraries
-
Rebex Mail Pack
IMAP, MS Graph, EWS, POP3, SMTP, MIME, S/MIME, MSG
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Folder operations
On this page:
The sample code on this page assumes you have already connected and authenticated to Microsoft 365 (Exchange Online) server.
Folder IDs
A folder ID uniquely identifies a folder at the Exchange Online (Microsoft 365) server.
In Rebex Graph, folder IDs are represented by GraphFolderId class.
// create Graph client, connect, log in
// ...
// get list of folders in the mailbox
GraphFolderCollection folders = client.GetFolderList();
// display IDs and names of those folders
foreach (GraphFolderInfo folder in folders)
{
Console.WriteLine("{0}: {1}", folder.Id, folder.Name);
}
Tip: To get a list of subfolders, use GetFolderList()
method and specify the GraphFolderId argument.
Tip: Accessing shared mailboxes is possible as well.
Well-known folder IDs
Well-known folders such as 'Inbox', 'Drafts' or 'Sent Items' are accessible using a set predefined folder IDs. These constant IDs are accessible through static properties of GraphFolderId class:
GraphFolderId.Root- The root folder.GraphFolderId.Inbox- The "Inbox" folder.GraphFolderId.Drafts- The "Drafts" folder.GraphFolderId.SentItems- The "Sent Items" folder.GraphFolderId.Outbox- The "Outbox" folder.GraphFolderId.Archive- The "Archive" folder.GraphFolderId.DeletedItems- The "Deleted Items" folder.GraphFolderId.Deletions- The "Deletions" folder.GraphFolderId.JunkEmail- The "Junk E-mail" folder.GraphFolderId.Scheduled- The "Scheduled" folder (also known as "Snoozed").GraphFolderId.SearchFolders- The "Search Folders" folder (also known as "Finder").
Getting list of subfolders
To get a list of subfolders, use GetFolderList() method:
// create Graph client instance, connect, log in // ... // find the 'Orders' folder (in the root folder) GraphFolderCollection folders = client.GetFolderList(); GraphFolderInfo folderOrders = folders.Where(s => s.Name == "Orders").First(); // list subfolders of the 'Orders' folder GraphFolderCollection subfolders = client.GetFolderList(folderOrders.Id);
Back to feature list...