[EWS]查找 文件夹
摘要
有时在操作exchange的时候,需要查找用户exchange文件夹,比如用户新建了一些文件夹。
一个例子
这里以查找用户outlook邮箱中的历史对话文件夹为例。
private const ExchangeVersion EXCHANGE_VERSION = ExchangeVersion.Exchange2010_SP2; private ExchangeService _service; public MyExchangeClient(UserInfo userInfo) { if (userInfo == null) { throw new ArgumentNullException("user is empty"); } this._userInfo = userInfo; this._service = new ExchangeService(EXCHANGE_VERSION); _service.Credentials = new NetworkCredential(userInfo.Itcode, userInfo.Pwd, _userInfo.Domain); _service.Url = new Uri(ConfigManager.ExchangeServerUrl); }
/// <summary> /// 查找对话历史文件夹 /// </summary> /// <returns></returns> private Folder FindImHistoryFolder() { int _pageSize = 10; FolderView folderView = new FolderView(_pageSize, 0); folderView.PropertySet = new PropertySet(BasePropertySet.IdOnly); folderView.PropertySet.Add(FolderSchema.DisplayName); folderView.PropertySet.Add(FolderSchema.ChildFolderCount); folderView.Traversal = FolderTraversal.Shallow; Folder imHistoryFolder = null; FindFoldersResults findFolderResults; bool foundImHistoryFolder = false; do { findFolderResults = this._service.FindFolders(WellKnownFolderName.MsgFolderRoot, folderView); foreach (Folder folder in findFolderResults) { if (folder.DisplayName.ToLower() == "conversation history" || folder.DisplayName.ToLower() == "对话历史记录") { imHistoryFolder = folder; foundImHistoryFolder = true; } } folderView.Offset += _pageSize; } while (findFolderResults.MoreAvailable && !foundImHistoryFolder); return imHistoryFolder; }
-
博客地址:http://www.cnblogs.com/wolf-sun/
博客版权:如果文中有不妥或者错误的地方还望高手的你指出,以免误人子弟。如果觉得本文对你有所帮助不如【推荐】一下!如果你有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。