Работа с папками на WebDav
Contents
[
Hide
]
Получение списка всех папок с сервера
API Aspose.Email предоставляет возможность подключаться к Exchange Server и перечислять все папки и подпапки. Вы также можете рекурсивно получить все подпапки из каждой папки. Эта статья показывает, как получить все подпапки с сервера Exchange и извлекать папки с постраничной навигацией.
Использование WebDav
Следующий фрагмент кода демонстрирует, как перечислить папки с Exchange Server.
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
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public static void Run() | |
{ | |
try | |
{ | |
ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator", "user", "pwd", "domain"); | |
Console.WriteLine("Downloading all messages from Inbox...."); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri); | |
string rootUri = client.GetMailboxInfo().RootUri; | |
// List all the folders from Exchange server | |
ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(rootUri); | |
foreach (ExchangeFolderInfo folderInfo in folderInfoCollection) | |
{ | |
// Call the recursive method to read messages and get sub-folders | |
ListSubFolders(client, folderInfo); | |
} | |
Console.WriteLine("All messages downloaded."); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
private static void ListSubFolders(ExchangeClient client, ExchangeFolderInfo folderInfo) | |
{ | |
Console.WriteLine(folderInfo.DisplayName); | |
try | |
{ | |
// If this folder has sub-folders, call this method recursively to get messages | |
ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderInfo.Uri); | |
foreach (ExchangeFolderInfo subfolderInfo in folderInfoCollection) | |
{ | |
ListSubFolders(client, subfolderInfo); | |
} | |
} | |
catch (Exception) | |
{ | |
} | |
} |