I have a document library with subfolders containing images. I'd like to traverse the subfolders and grab the URLs of those images so that I can display them on my little js web app I'm whipping up.

I can only seem to get the root of the document library using SPServices' GetListItems. I've tried passing in "library/subfolder" as the list name, but that didn't work.

Is there a way to do this?

2 Answers 2


You'll want to add a CAMLQuery option to your GetListItems call:

CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope="Recursive"/></QueryOptions>",

This will result in the recursive querying of all the subfolders.

  • 1
    I think every SharePoint developer is bound by fate to ask and receive this answer at least once.
    – Kit Menke
    Apr 3, 2012 at 19:59
  • This helped a lot. One more QueryOption that helped was <Folder></Folder>. It needs to be in a certain format: <Folder>Libraryroot/folder/subfolder</Folder>
    – nfw
    Apr 3, 2012 at 22:56

The best would be to use SPQuery to get your items, but use the Folder property on each list item (starting from Root folder) and check for "null" (this will tell you if you hit a folder or a simple item). Alternative, use same SPQuery but rely on content type query meaning "Get all items of a certain Content Type" and use FOLDER as the query.

Exact example have a look here http://avinashkt.blogspot.com/2010/03/spfolder-related-operations-in.html

Hope it helps, C:\Marius

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.