CAML query that includes folders in result set

前端 未结 7 1868
孤街浪徒
孤街浪徒 2020-12-16 01:29

I\'m trying to write a CAML query that executes against a specific SPList, scoped to a specific folder, recursive from that point, and returns all ListItems (which meet a cr

7条回答
  •  不知归路
    2020-12-16 02:06

    This still seems to an issue in SP 2010. Here's workaround code that will work for 2007 or 2010, based on this MSDN Forums post that uses the web services:

    private static SPListItem RecurseIntoFolders(SPList list, SPFolder parentFolder, string fileReference)
    {
        var query = new SPQuery
        {
            Query = "" +
                    "1" +
                    "",
            ViewFields = String.Format("", FileReferenceInternalFieldName),
            ViewAttributes = "Scope='RecursiveAll'",
            Folder = parentFolder
        };
    
        var items = list.GetItems(query);
        if (items.Count == 0)
            return null;
    
        foreach (SPListItem item in items)
        {
            parentFolder = item.Folder;
    
            // TODO: Any other checking that this is the item we want
    
            return item;
        }
        return RecurseIntoFolders(list, parentFolder, fileReference);
    }
    

提交回复
热议问题