Làm việc với thư mục trên WebDav
Contents
[
Hide
]
Liệt kê tất cả các thư mục từ máy chủ
API Aspose.Email cung cấp khả năng kết nối tới Exchange Server và liệt kê tất cả các thư mục và thư mục con. Bạn cũng có thể lấy tất cả các thư mục con từ mỗi thư mục một cách đệ quy. Bài viết này cho thấy cách lấy tất cả các thư mục con từ Exchange server và lấy các thư mục theo phân trang.
Sử dụng WebDav
Đoạn mã sau đây cho bạn thấy cách liệt kê các thư mục từ 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);
}
}