0

So this is my query to count items in given folder:

/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents/')/ItemCount

And it gives me count of all elements but how I can count only folders inside /Shared%20Documents/ ?

1

You can examine the returned XML to find related querries for your request...

There is no nice way to just pull the folder count, but you can use the /folders to retrieve all folders below the current node.

See this line from the returned XML for your query:

<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Folders" type="application/atom+xml;type=feed" title="Folders" href="Web/GetFolderByServerRelativePath(decodedurl='/teams/TeamsiteTestHeiko/Shared%20Documents')/Folders" />
<title />

Calling that on my root DocLib with 2 folders returns the correct answer of 3 folders since you will also be getting the Forms folder in the root level.

Hope that helps

  • I did it the same way. I just get basic info about all folders and count them. I was just looking for nicer way to do it. – Krzysztof Majewski Jun 19 '18 at 8:11
  • I am guessing this will become a tree view. Only fetch the items once you expand a folder. Show the expand icon regardless and remove it onClick if no items are returned, if items come back. This can save a ton of requests – Heiko Hatzfeld_MSFT Jun 19 '18 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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