Frage

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!

War es hilfreich?

Lösung

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>'
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top