使用 WebDav 处理文件夹
Contents
[
Hide
]
列出服务器上的所有文件夹
Aspose.Email API 提供了连接到 Exchange Server 并列出所有文件夹和子文件夹的功能。您还可以递归检索每个文件夹的所有子文件夹。本文展示了如何从 Exchange Server 检索所有子文件夹以及使用分页检索文件夹。
使用 WebDav
以下代码片段展示了如何列出 Exchange Server 的文件夹。
public static void run() {
try {
ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator", "user", "pwd", "domain");
System.out.println("Downloading all messages from Inbox....");
ExchangeMailboxInfo mailboxInfo = client.getMailboxInfo();
System.out.println("Mailbox URI: " + mailboxInfo.getMailboxUri());
String rootUri = client.getMailboxInfo().getRootUri();
// List all the folders from Exchange server
ExchangeFolderInfoCollection folderInfoCollection = client.listSubFolders(rootUri);
for (ExchangeFolderInfo folderInfo : folderInfoCollection) {
// Call the recursive method to read messages and get sub-folders
listSubFolders(client, folderInfo);
}
System.out.println("All messages downloaded.");
} catch (Exception ex) {
System.err.println(ex);
}
}
private static void listSubFolders(ExchangeClient client, ExchangeFolderInfo folderInfo) {
System.out.println(folderInfo.getDisplayName());
try {
// If this folder has sub-folders, call this method recursively to get messages
ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderInfo.Uri);
for (ExchangeFolderInfo subfolderInfo : folderInfoCollection) {
listSubFolders(client, subfolderInfo);
}
} catch (Exception ex) {
System.err.println(ex);
}
}