C# · 12月 21, 2021

[EWS]查找 文件夹

摘要

有时在操作exchange的时候,需要查找用户exchange文件夹,比如用户新建了一些文件夹。

一个例子

这里以查找用户outlook邮箱中的历史对话文件夹为例。

ExchangeVersion EXCHANGE_VERSION = </span><span style=”color: #0000ff;”&gt;public</span><span style=”color: #000000;”&gt; MyExchangeClient(UserInfo userInfo) { </span><span style=”color: #0000ff;”&gt;if</span> (userInfo == <span style=”color: #0000ff;”&gt;null</span><span style=”color: #000000;”&gt;) { </span><span style=”color: #0000ff;”&gt;throw</span> <span style=”color: #0000ff;”&gt;new</span> ArgumentNullException(<span style=”color: #800000;”&gt;”</span><span style=”color: #800000;”&gt;user is empty</span><span style=”color: #800000;”&gt;”</span><span style=”color: #000000;”&gt;); } </span><span style=”color: #0000ff;”&gt;this</span>._userInfo =<span style=”color: #000000;”&gt; userInfo; </span><span style=”color: #0000ff;”&gt;this</span>._service = <span style=”color: #0000ff;”&gt;new</span><span style=”color: #000000;”&gt; ExchangeService(EXCHANGE_VERSION);

_service.Credentials = <span style=”color: #0000ff;”>new<span style=”color: #000000;”> NetworkCredential(userInfo.Itcode,userInfo.Pwd,_userInfo.Domain);
_service.Url = <span style=”color: #0000ff;”>new<span style=”color: #000000;”> Uri(ConfigManager.ExchangeServerUrl);

}</span></pre> _pageSize = = FolderView(_pageSize,= folderView.Traversal </span>=<span style=”color: #000000;”&gt; FolderTraversal.Shallow; Folder imHistoryFolder </span>= <span style=”color: #0000ff;”&gt;null</span><span style=”color: #000000;”&gt;; FindFoldersResults findFolderResults; </span><span style=”color: #0000ff;”&gt;bool</span> foundImHistoryFolder = <span style=”color: #0000ff;”&gt;false</span><span style=”color: #000000;”&gt;; </span><span style=”color: #0000ff;”&gt;do</span><span style=”color: #000000;”&gt; { findFolderResults </span>= <span style=”color: #0000ff;”&gt;this</span><span style=”color: #000000;”&gt;._service.FindFolders(WellK<a href=”https://www.jb51.cc/tag/Now/” target=”_blank” class=”keywords”>Now</a>nFolderName.MsgFolderRoot,folderView); </span><span style=”color: #0000ff;”&gt;foreach</span> (Folder folder <span style=”color: #0000ff;”&gt;in</span><span style=”color: #000000;”&gt; findFolderResults) { </span><span style=”color: #0000ff;”&gt;if</span> (folder.DisplayName.ToLower() == <span style=”color: #800000;”&gt;”</span><span style=”color: #800000;”&gt;conversation history</span><span style=”color: #800000;”&gt;”</span> || folder.DisplayName.ToLower() == <span style=”color: #800000;”&gt;”</span><span style=”color: #800000;”&gt;对话历史记录</span><span style=”color: #800000;”&gt;”</span><span style=”color: #000000;”&gt;) { imHistoryFolder </span>=<span style=”color: #000000;”&gt; folder; foundImHistoryFolder </span>= <span style=”color: #0000ff;”&gt;true</span><span style=”color: #000000;”&gt;; } } folderView.Offset </span>+=<span style=”color: #000000;”&gt; _pageSize; } </span><span style=”color: #0000ff;”&gt;while</span> (findFolderResults.MoreAvailable &amp;&amp; !<span style=”color: #000000;”&gt;foundImHistoryFolder); </span><span style=”color: #0000ff;”&gt;return</span><span style=”color: #000000;”&gt; imHistoryFolder; }</span></pre>