无法在Sharepoint中获取List's子文件夹

本文关键字:文件夹 List Sharepoint 获取 | 更新日期: 2023-09-27 18:05:58

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

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,我没有得到任何东西。我的意思是,当我传递链接-"http://SITE/DocLst/Входящие"从"ows_encoded荒诞"到"QueryOptions -文件夹"-我得到只是在调用getlisttitems时没有任何回报。

0行。

我能做错什么?

编辑:由于人们怀疑微软的msdn是一个"可疑链接",这里是我的源代码(稍微修改了链接的代码)。

    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;
        ...
    }

当我在"获取子文件夹内容"代码后评估oNodes时,我看到零行,而应该有"Входящие"文件夹的子文件夹列表。

无法在Sharepoint中获取List's子文件夹

事实证明,我从msdn中使用的示例是不正确的。将"ows_encoded荒诞"的值粘贴到"Folder"queryOption中将不起作用,因为需要一个相对路径。

" ows_encoded荒诞"返回"http://SITE/DocList/Folder"而"DocList/Folder"是"Folder"选项正常工作所必需的