SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
I think every SharePoint developer is bound by fate to ask and receive this answer at least once. – Kit Menke Apr 3 '12 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 '12 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

Hope it helps, C:\Marius

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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