0

I'm working on an Angular2 component that needs to expose the files in a document library but also the files within any subfolders of said document library. I've scoured the web for an answer and it looks like this is very doable -- I just seem to be coming up short.

The REST call is somewhat abnormal -- it's a search rather than a request for the document library:

_api/search/query?querytext='ListId:{{The List ID}} AND FileName<>"AllItems.aspx*"'

When I run this query with with no property limits I don't immediately see anything in the OData returned that would keep track of any subfolders' contents. I'm hoping maybe I can add an $expand that would take care of it?

Any help or insight would be greatly appreciated!

0

You can generally query your items using caml in the REST api like this:

var camlQuery = {
    ViewXml: "<View>" +
        "<Query></Query>" +
        "</View>"
}

then call /_api/Web/Lists/getById('YourListId')/GetItems(query=@v1)?@v1=' + JSON.stringify(camlQuery)

see this question on CAML and the REST-api, documentation is at GetItems-method.

Now, querying "items in a folder" should work like this (untested):

<View>
  <Query />
  <QueryOptions>
    <Folder>http://MySharePointServer/Root/SubFolder1</Folder>    
  </QueryOptions>
<View>

Have a look at this question, regarding CAML and folders.

However, reading the docs to SP.CamlQuery the following sounds promising, too:

var camlQuery = {
    FolderServerRelativeUrl: 'http://MySharePointServer/Root/SubFolder1',
    ViewXml: '<View><Query /></View>'
}
  • Many thanks Nils! I'm looking into the CAML approach now. I think one issue I'm having with other, similar posts is that I don't know what the subfolders will be. There will be document library "x", and inside that will be some documents I need information on but there will also possibly be folders made by users. If there are folders, I'd need to display all the the documents inside those folders as well without additional REST calls. Seems like your CAML recommendations are getting me much closer to that. – Sam P Jul 11 '17 at 14:51
  • You're welcome. If the answer was helpful, consider marking it as such. – Nils Jul 20 '17 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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