Getting size of a Sharepoint Subsite using CSOM

49 views Asked by At

I hope someone can point me out on the right direction here.

I'm trying to get the storage used by a subsite for my app on C#. I found PnP.PowerShell has a nice solution for this: https://pnp.github.io/powershell/cmdlets/Get-PnPFolderStorageMetric.html

Looking at the code, it use the Web object of the subsite to get the Folder object of itself containing the expresions "StorageMetrics" https://github.com/pnp/powershell/blob/dev/src/Commands/Files/GetFolderStorageMetric.cs

PnP.PowerShell use directly PnP.Core for this task. https://github.com/pnp/pnpcore/blob/dev/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/Web.cs?#L395-L408

PnP.Core seems making calls to the API: _api/Web/getFolderByServerRelativePath(decodedUrl='{encodedServerRelativeUrl}')

I'm not sure how the PnP.Core add the expresions when calling the API or what additional info is required for the body. I only saw this information on regards this API: Sharepoint REST API GetFolderByServerRelativePath returns error when percent sign (%) is used in a folder name

Meanwhile, I've tried to use directly CSOM to get the the storage metrics of the subsite as a folder: https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.client.web.getfolderbyserverrelativepath?view=sharepoint-csom

I use the subsite as context and then the subsite server relative url to get the subsite itself as folder (trying to replicate here the same as I see on PnP.PowerShell) and check the storage metrics. I don't get any errors (if I use the Site collection as context, I do get errors), so I can assume the code is correct. But the 'TotalSize' property is always 0. It seems something is not loading correctly, or something is missing but doesn't bring errors.

Can anyone clarify if this is possible to do usin CSOM and how? or in case only the REST API is feasible, how to make the call correctly to get the storage metrics?

I've also tried the API https://Domain.sharepoint.com/sites/SiteName/SubSiteName/_api/Web/GetFolderByServerRelativePath(decodedurl='/sites/SiteName/SubSiteName')/StorageMetrics

The results are the same as the CSOM, 0 TotalSize and 0 TotalFIleCount

0

There are 0 answers