0

I'm accessing a SharePoint folder that contains two files and a subfolder. I'm getting back a correct ItemCount but no list of items. Using a made-up path of /sites/sitename/folder1/folder1, and hence the following URI:

https://myplace.sharepoint.com/sites/sitename/_api/web/GetFolderByServerRelativeUrl('/sites/sitename/folder1/folder2')?$expand=Files,Folders

The result comes out looking like:

{
  "d": {
    "__metadata": {
      "id": "https://myplace.sharepoint.com/sites/sitename/_api/Web/GetFolderByServerRelativePath(decodedurl='/sites/sitename/folder1/folder2')",
      "uri": "https://myplace.sharepoint.com/sites/sitename/_api/Web/GetFolderByServerRelativePath(decodedurl='/sites/sitename/folder1/folder2')",
      "type": "SP.Folder"
    },
    "Files": {
      "results": []
    },
    "ListItemAllFields": {
      "__deferred": {
        "uri": "https://myplace.sharepoint.com/sites/sitename/_api/Web/GetFolderByServerRelativePath(decodedurl='/sites/sitename/folder1/folder2')/ListItemAllFields"
      }
    },
    "ParentFolder": {
      "__deferred": {
        "uri": "https://myplace.sharepoint.com/sites/sitename/_api/Web/GetFolderByServerRelativePath(decodedurl='/sites/sitename/folder1/folder2')/ParentFolder"
      }
    },
    "Properties": {
      "__deferred": {
        "uri": https://myplace.sharepoint.com/sites/sitename/_api/Web/GetFolderByServerRelativePath(decodedurl='/sites/sitename/folder1/folder2')/Properties"
      }
    },
    "StorageMetrics": {
      "__deferred": {
        "uri": https://myplace.sharepoint.com/sites/sitename/_api/Web/GetFolderByServerRelativePath(decodedurl='/sites/sitename/folder1/folder2')/StorageMetrics"
      }
    },
    "Folders": {
      "results": []
    },
    "Exists": true,
    "IsWOPIEnabled": false,
    "ItemCount": 3,
    "Name": "folder2",
    "ProgID": null,
    "ServerRelativeUrl": "/sites/sitename/folder1/folder2",
    "TimeCreated": "2023-06-23T12:20:23Z",
    "TimeLastModified": "2023-06-27T11:06:16Z",
    "UniqueId": "12345678-1234-4321-8765-001234567890",
    "WelcomePage": ""
  }
}

I can see an ItemCount of 3 there, which seems to reflect my two files and a folder (and that number changes if I add/remove things in the web interface) but why am I getting an empty list of 'Folders' and 'Files'?

I thank you in advance for whatever thing it is that I'm missing!

1 Answer 1

0

Not sure if it is possible to get items from a list this way. The best way to query a list is to use the RenderListDataAsStream API. You need to specify the FolderServerRelativeUrl parameter to limit your query to a folder. You can either use the ViewXml parameter to specify a CAML query, starting with a <View> element. That is the most flexible option. There is also the simpler FilterValue1 etc. parameters that are user from the SharePoint list web interface.

3
  • Is that a list? The path I'm using is taken from the web interface where I'm presented with a folder-like display with the files in it. Since the API is returning a structure with an ItemCount of 3, I was expecting to be able to 'see' those three items. Somehow... Jun 27 at 13:35
  • From an API perspective, lists and document libraries are the same. Jun 27 at 14:02
  • You're losing me in nomenclature there I'm afraid - I'm new to Sharepoint except for having used it essentially as a file store using the web interface for a while. I see it as a normal hierarchical structure of folders and documents with some attributes and 'check out/check in' ability. Hence, I was foreseeing it like a file system where I can give it a reference to a 'folder' and ask for a list of files and folders within that folder. Seems I may have been too simplistic. Jun 27 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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