SharePoint REST API getFolderByServerRelativeUrl Returns Nothing

送分小仙女□ 提交于 2019-12-11 12:41:37

问题


I would like to drill into the library and then into a specified folder, but I am having problems getting 'getFolderByServerRelativeUrl' to grab anything for me.

This http://_base/_api/web/getFolderByServerRelativeUrl('LibName')/files returns zero results. But if I use http://_base/_api/web/lists/getbytitle('LibName')/items it returns multiple items.


回答1:


/_api/web/lists/getbytitle('<list title>')/items endpoint returns all list items within a library, /_api/web/getFolderByServerRelativeUrl('<url>')/files returns only files located under (one level beneath only) the specified folder.

Example

Assume the following Documents library structure:

Documents (library)
   |
   Guides (folder)
     |
     SharePoint User Guide.docx (file)

Then, the following request:

/_api/web/lists/getbytitle('Documents')/items will return 2 items:

  • list item associated with Guides folder
  • list item associated with file

At the same time, the request: /_api/web/getFolderByServerRelativeUrl('Documents')/files

will returns 0 files since there are no files contained in the root folder

but the request with provided folder url: /_api/web/getFolderByServerRelativeUrl('Documents/Guides')/files

will return SharePoint User Guide.docx file.




回答2:


You're using the wrong URL. Try appending it to the other URL.



来源:https://stackoverflow.com/questions/31662643/sharepoint-rest-api-getfolderbyserverrelativeurl-returns-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!