Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 4 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
1  
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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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.