Question

When using the ItemCount function on the / folder, the count is 0.

The result of GET /_api/web/GetFolderByServerRelativeUrl('/')/ItemCount is:

{
  "d": {
    "ItemCount": 0
  }
}

But the content is actually not empty as it contains all the system related files as well as the user created libraries.

I can't seem to find anything about this on google or the sharepoint api documentation.

Is there another way to get it? I know it's possible to count items in a library using the list functions, but a folder is not list.

Was it helpful?

Solution

I think you are facing a similar restriction as in this existing question: Getting an ItemCount with filtering in SP2013 using REST api.

To quote Vadim:

"The ItemCount function could be applied to List resource [...] but not to ListItemCollection resource".

This same restriction would apply to FileCollection resource and FolderCollection resource, which - if I'm correct - the / level would represent either of.

ItemCount's description is the following:

Gets a value that specifies the count of items in the list folder.

This would mean, that a sub-directory (i.e. a type of SP.Folder) would be applicable

(source)

Note, that by using GetFolderByServerRelativeUrl can be returned items, so e.g. Folders would be excluded.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top