-2

I need to get files from "Shared Folders" list. They are nested into several subfolders, it goes like this:

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

I used this question's answer's source code 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/Входящие" from the "ows_EncodedAbsUrl" to the "QueryOptions - Folder" - I get just nothing in return when calling GetListItems. Zero rows.

What I can be doing wrong?

EDIT: Since people suspect microsoft's msdn is a "suspect link" here is my source code (slightly modified code from the 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;

        ...
    }

When I evaluate the oNodes after the "Get subfolder contents" code, I see zero rows, while there should be a list of subfolders of the "Входящие" folder.

Istrebitel
  • 2,963
  • 6
  • 34
  • 49
  • we are not going to click on links that look to be suspect so to speak.. post your actual code and perhaps someone can spot what you are doing incorrectly also if you are passing a link perhaps you should try using the debugger to step through the code.. start setting some breakpoints – MethodMan Jul 31 '15 at 15:14
  • What!? Microsoft's msdn is suspect? – Istrebitel Jul 31 '15 at 15:14
  • And obviously I've debugged it that's why I know there are zero rows – Istrebitel Jul 31 '15 at 15:20
  • it's not obvious it would only be obvious if you initially stated that.. anyway what line in your code are you expecting to return rows.. perhaps you are not using XPath properly in your code what does the xml look like please show all relevant code that pertains to your question http://stackoverflow.com/questions/809496/why-is-selectsinglenode-returning-null – MethodMan Jul 31 '15 at 15:23
  • the problem is not that xml is null, the problem is that the xml returned is "\n" meaning there are no rows where there should be about 10 – Istrebitel Jul 31 '15 at 15:28

1 Answers1

0

Turns out, the example I was using from msdn was incorrect. Pasting the value of "ows_EncodedAbsUrl" into "Folder" queryOption will not work, because a relative path is required.

"ows_EncodedAbsUrl" was returning "http://SITE/DocList/Folder" while "DocList/Folder" is required for the "Folder" option to work properly.

Istrebitel
  • 2,963
  • 6
  • 34
  • 49