无法在 Sharepoint 中获取列表的子文件夹

Cannot get List's subfolders in Sharepoint

我需要从 "Shared Folders" 列表中获取文件。它们嵌套在几个子文件夹中,如下所示:

Shared Folders
 \- Incoming Documents
     \- Work Trips
         \- ####(code)
             \- the file I'm looking for

我使用了这个问题的答案的源代码 https://social.msdn.microsoft.com/Forums/office/en-US/16a2d993-2f5e-4242-8e5a-451a78c064a3/retrieving-folders-from-document-library?forum=sharepointdevelopmentlegacy and I'm not getting anything. I mean, when I'm passing the link - "http://SITE/DocLst/Входящие" 从 "ows_EncodedAbsUrl" 到 "QueryOptions - Folder" - 我在调用 GetListItems 时在 return 中什么也没有得到。零行。

我可能做错了什么?

编辑:由于人们怀疑微软的 msdn 是 "suspect link",这里是我的源代码(从 link 稍微修改了代码)。

    static void FillNodes(string querytext, out XmlNode query, out XmlNode viewFields, out XmlNode queryOptions)
    {
        XmlDocument xmlDoc = new System.Xml.XmlDocument();
        xmlDoc.LoadXml(querytext);
        query = xmlDoc.SelectSingleNode("//Query");
        viewFields = xmlDoc.SelectSingleNode("//ViewFields");
        queryOptions = xmlDoc.SelectSingleNode("//QueryOptions");
    }

    static XmlNode GetFoldersNode(XmlNodeList oNodes)
    {
        // Find the node with root folders
        XmlNode folderNode = null;
        foreach (XmlNode node in oNodes)
        {
            if (node.ChildNodes.Count == 0)
                continue;
            folderNode = node;
            break;
        }
        if (folderNode == null)
            throw new Exception("Folders not found!");

        return folderNode;
    }
    static string FindFolder(XmlNode folderNode, string folderName)
    {
        string folderPath = null;
        foreach (XmlNode node in folderNode.ChildNodes)
        {
            if (node.Attributes == null || node.Attributes["ows_EncodedAbsUrl"] == null)
                continue;
            if (!node.Attributes["ows_EncodedAbsUrl"].Value.Contains(folderName))
                continue;
            folderPath = node.Attributes["ows_EncodedAbsUrl"].Value;
            break;
        }
        return folderPath;
    }

    static void Main(string[] args)
    {
        XmlDocument resdoc = new System.Xml.XmlDocument();
        XmlNode resnode = null;
        string strURL = "";
        string strFileName = "";

        sharepointsrv.Lists objLists = new sharepointsrv.Lists();
        objLists.Credentials = new System.Net.NetworkCredential("(login)", "(pw)", "(domain)");
        objLists.Url = "http://(site)/_vti_bin/lists.asmx";

        XmlNode ndQuery;
        XmlNode ndViewFields;
        XmlNode ndQueryOptions;
        FillNodes("<mylistitemrequest><Query><Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Lookup\">1</Value></Eq></Where></Query><ViewFields><FieldRef Name=\"EncodedAbsUrl\"/><FieldRef Name=\"ID\" /><FieldRef Name=\"FileRef\" /><FieldRef Name=\"ID\" /><FieldRef Name=\"Title\" /></ViewFields><QueryOptions></QueryOptions></mylistitemrequest>",
            out ndQuery, out ndViewFields, out ndQueryOptions);

        XmlNode ndListItems;
        XmlNodeList oNodes;
        XmlNode folderNode;
        string folderPath;
        // Get top level folders
        ndListItems = objLists.GetListItems("Общие документы", null, ndQuery, ndViewFields, null, ndQueryOptions, null); 
        oNodes = ndListItems.ChildNodes;

        // Find the node with root folders
        folderNode = GetFoldersNode(oNodes);

        // Find the "Входящие" folder
        folderPath = FindFolder(folderNode, "Входящие");

        FillNodes("<mylistitemrequest><Query><Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Lookup\">1</Value></Eq></Where></Query><ViewFields><FieldRef Name=\"EncodedAbsUrl\"/><FieldRef Name=\"ID\" /><FieldRef Name=\"Title\" /></ViewFields><QueryOptions><Folder>" + folderPath + "</Folder></QueryOptions></mylistitemrequest>",
            out ndQuery, out ndViewFields, out ndQueryOptions);

        // Get subfolder contents
        ndListItems = objLists.GetListItems("Общие документы", null, ndQuery, ndViewFields, null, ndQueryOptions, null);
        oNodes = ndListItems.ChildNodes;

        // At this point I am getting zero rows, even though I should be getting multiple folders
        // Following code digs deeper down the hierarchy of folders, but it's not working because nothing arrives at this point

        // Get node with folders
        folderNode = GetFoldersNode(oNodes);

        // Get "Командировки" folder
        folderPath = FindFolder(folderNode, "Командировки");

        // Get subfolder contents
        ndListItems = objLists.GetListItems("Общие документы", null, ndQuery, ndViewFields, null, ndQueryOptions, null);
        oNodes = ndListItems.ChildNodes;

        ...
    }

当我计算 "Get subfolder contents" 代码后的 oNodes 时,我看到零行,而应该有“Входящие”文件夹的子文件夹列表。

事实证明,我在 msdn 中使用的示例不正确。将 "ows_EncodedAbsUrl" 的值粘贴到 "Folder" queryOption 中将不起作用,因为需要相对路径。

"ows_EncodedAbsUrl" 返回“http://SITE/DocList/Folder”,而 "Folder" 选项需要 "DocList/Folder" 才能正常工作。