通过给它的路径名称搜索公共文件夹的文件夹 [英] Searching Of Folders in Public Folders by giving its PATH Name

查看:254
本文介绍了通过给它的路径名称搜索公共文件夹的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能通过使用Exchange Web服务(EWS)托管API给文件夹的路径来搜索公共文件夹所有文件夹和sufolders?

Is it possible to search for all folders and sufolders in public folders by giving the path of the folders by using Exchange Web Service(EWS) Managed Api?

推荐答案

您只能在文件夹中搜索,深度只有一层上EWS所以:

You can only search within folders, one level deep on EWS so for:

"PublicFoldersRoot\subjectA\sectionB\partC\"

我要搜索subjectA文件夹中,那么一旦我有FolderId然后我会再搜索sectionB文件夹,依此类推,直到我发现我所需要的。

I would search for "subjectA" folder, then once I have that FolderId then I would then search for "sectionB" folder and so on until I find what I need.

该方法 GetPublicFolderByPath 将路径subjectA \\ sectonB \\ partC \\和分裂的道路到文件夹名称的数组,然后找出每个文件夹递归。

The method GetPublicFolderByPath takes the path "subjectA\sectonB\partC\" and splits the path into an array of folder names, then finds each folder recursively.

public Folder GetPublicFolderByPath(ExchangeService service, String ewsFolderPath)
{
    String[] folders = ewsFolderPath.Split('\');

    Folder parentFolderId = null;
    Folder actualFolder = null;

    for (int i = 0; i < folders.Count(); i++)
    {
        if (0 == i)
        {
            parentFolderId = GetTopLevelFolder(service, folders[i]);// for first first loop public folder root is the parent
            actualFolder = parentFolderId; //in case folders[] is only one long
        }
        else
        {
            actualFolder = GetFolder(service, parentFolderId.Id, folders[i]);
            parentFolderId = actualFolder;
        }
    }
    return actualFolder;
}

该方法 GetTopLevelFolder 获得第一个文件夹,部1.这是公共文件夹根又​​名的WellKnownFolderName.PublicFoldersRoot的孩子。

The method GetTopLevelFolder gets the first folder, "sectionA" which is a child of the public folders root a.k.a. "WellKnownFolderName.PublicFoldersRoot".

private Folder GetTopLevelFolder(ExchangeService service, String folderName)
{
    FolderView folderView = new FolderView(int.MaxValue);
    FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, folderView);

    foreach (Folder folder in findFolderResults)
    {
        if (folderName.Equals(folder.DisplayName, StringComparison.InvariantCultureIgnoreCase))
        {
            return folder;
        }
    }
    throw new Exception("Top Level Folder not found: " + folderName);
}

的GetFolder 方法需要家长FolderId并搜查所有的孩子文件夹上的名字提供了一个匹配,并返回FolderId你要求的孩子。

The GetFolder method takes a parent FolderId and searched all of the children folders for a match on the name provides and returns the child FolderId you have requested.

private Folder GetFolder(ExchangeService service, FolderId ParentFolderId, String folderName)
{
    FolderView folderView = new FolderView(int.MaxValue);
    FindFoldersResults findFolderResults = service.FindFolders(ParentFolderId, folderView);

    foreach (Folder folder in findFolderResults)
    {
        if (folderName.Equals(folder.DisplayName, StringComparison.InvariantCultureIgnoreCase))
        {
            return folder;
        }
    }

    throw new Exception("Folder not found: " + folderName);
}

请注意,我用的是Microsoft.Exchange.WebServices管理API DLL,为 HTTPS类似的想法://yourexchangeserver/ews/services.w​​sdl 。从路径中使用得到一个文件夹中创建ExchangeService对象,然后写:

Please note that I am using the Microsoft.Exchange.WebServices managed API dll, similar idea for https://yourexchangeserver/ews/services.wsdl. To get a folder from the path use create the ExchangeService object then write:

GetPublicFolderByPath(service, "subjectA\sectionB\partC\")

请了票,如果这可以帮助你:)

Please up-vote if this helps you :)

这篇关于通过给它的路径名称搜索公共文件夹的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆