SharePoint API GetFolderByServerRelativeUrl / Files API does not return a 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 I have a resolution that I have wrong or if I don't understand it properly.

when i use a browser to access my url:

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

      

the xml part that is returned says that there are 87 elements <d:ItemCount m:type="Edm.Int32">87</d:ItemCount>

that correlate correctly with the number of files inside this folder.

Here's where I got confused. When I use the following to show the contents of a folder, I don't get any information about the file specified in the result XML file, as I would expect:

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

      

I also tried the following to get information about a specific file, 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?

+3


source to share


2 answers


This happens because the wrong web context for the SP.Web.getFolderByServerRelativeUrl Method is specified in the REST request:

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

      

Let's assume the following site structure:

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

      

Then the following REST request:



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 the 2008

library folder Documents

under the site Archive

.

+8


source


Believe it or not, my problem was sending the parameter with a double quote instead of a single quote

well:

https://[server]/[web]/_api/web/GetFolderByServerRelativeUrl('/[web]/[library]/[folder]')

      



badly:

https://[server]/[web]/_api/web/GetFolderByServerRelativeUrl("/[web]/[library]/[folder]")

      

0


source







All Articles