Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharePoint GetFolderByServerRelativeUrl /Files API not returning list of files as expected

I'm new to SharePoint and I'm having trouble with a few of the simple examples I've found and I'm not sure if there's a permission I don't have correct or if I'm not understanding this properly.

when I use a browser to access my URL:

https://mysite.com/_api/web/GetFolderByServerRelativeUrl('/SCF/Shared%20Documents/FY%202014%20Memos')

part of the return xml says there are 87 items <d:ItemCount m:type="Edm.Int32">87</d:ItemCount>, which does correctly correlate to the number of files inside this folder.

Here's where I get confused. When I use the following to show the contents of the folder, I don't get any of the file information listed in the result xml like I would expect:

https://mysite.com/_api/web/GetFolderByServerRelativeUrl('/SCF/Shared%20Documents/FY%202014%20Memos')/Files

I've also tried the following to get specific file info, but I get a file not found message:

https://mysite.com/_api/web/GetFolderByServerRelativeUrl('/SCF/Shared%20Documents/FY%202014%20Memos/096.pdf')

Am I missing something simple?

like image 711
Chris_001 Avatar asked Dec 01 '14 23:12

Chris_001


1 Answers

This behavior occurs since the incorrect context of web for SP.Web.getFolderByServerRelativeUrl Method is specified in REST query:

https://[server]/[web]/_api/web/GetFolderByServerRelativeUrl('/[web]/[library]/[folder]')
                   |
                   web site from which Folder/Files are retrieved   

Assume the following site structure:

/ News web (root)
    |
    Archive sub web
       |
        Documents library
            |
            2008 Folder 

Then the following REST query:

https://[server]/archive/_api/web/GetFolderByServerRelativeUrl('/archive/Documents/2008')/Files

or

https://[server]/archive/_api/web/GetFolderByServerRelativeUrl('Documents/2008')/Files

will return the files located in 2008 folder of Documents library under Archive sub site.

like image 84
Vadim Gremyachev Avatar answered Oct 29 '22 13:10

Vadim Gremyachev