0

I need to know if there is a way to return all files and document sets in a recursive object.

I've written this code and it returns all folders and document sets but only as a flat list.

SPQuery query = new SPQuery();
query.Query = @"<Where>
                    <Eq>
                        <FieldRef Name='FSObjType' />
                        <Value Type='Lookup'>1</Value>
                    </Eq>
                </Where>";
query.ViewAttributes = "Scope=\"RecursiveAll\""; // get both files and document sets
//query.ViewAttributes = "Scope=\"Recursive\""; // only fetches document sets

var result = list.GetItems(query);

Any advice?

Thanks

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
Eric Herlitz
  • 25,354
  • 27
  • 113
  • 157
  • 1
    “Caml” is a family of programming languages, the first having been released in 1985, and the most recent one month ago. I changed your title to “CAML” as it appears this is what you meant. – Pascal Cuoq Nov 01 '12 at 10:14

1 Answers1

1

By "recursive object," do you mean that you want results to be organized hierarchically? If so, that is not how the SPListItemCollection works. All of the resulting items are returned as siblings within the collection. If you want a hierarchy, I think you'll need to build it yourself using the flat results and perhaps a field like FileDirRef.

Rich Bennema
  • 10,295
  • 4
  • 37
  • 58