Forum Discussion
SiteProperties.WebsCount property is returning zero (CSOM)
Hi Pieter Veenstra - I'm pretty sure it's not related to CSOM. I'm getting the same results with a few versions of CSOM.
The Microsoft Support Engineer I'm working with has been able to reproduce the issue. He suggested using the "GetSitePropertiesByUrl" method. However, I did some testing and the data returned from the "GetSiteProperties" method does not match the data returned from the "GetSitePropertiesByUrl" method for the same site collection. (TimeZoneID, WebsCount, StorageUsage, LastContentModifiedDate)
He's working to get confirmation from the product group that this is expected behavior or not. I don't see how this can be anything other than a bug.
The Microsoft Support Engineer is trying to confirm with the product group that this was intentional.
- Maria ReinbachFeb 09, 2017Copper Contributor
Did you hear back from the MS engineer? I'm experiencing the same issue.
- DeletedFeb 10, 2017
Yes, I did. The product group confirmed that this is working as expected (I asked them to please update the documentation).
Several of these properties aren't populating (like they did in the past) because of the excessive work it takes to do so. Instead of getting the details in one call, you have to loop through all of the site collections and get the details for each one.
Here's the code that we implemented (C# / CSOM): [we use a DataTable to store the info]
using (ClientContext adminContext = new ClientContext(AdminSC)) { int startIndex = 0; adminContext.Credentials = new SharePointOnlineCredentials(SCAUserName, SCAPassword); var tenant = new Tenant(adminContext); SPOSitePropertiesEnumerable spp = null; while (spp == null || spp.Count > 0) { spp = tenant.GetSiteProperties(startIndex, true); //even though details is set to true it won't work adminContext.Load(spp); adminContext.ExecuteQuery(); foreach (SiteProperties sp in spp) { SiteProperties sprops = tenant.GetSitePropertiesByUrl(sp.Url, true); adminContext.Load(sprops); adminContext.ExecuteQuery(); DataRow myRow = dtSiteStats.NewRow(); myRow["SiteCollectionURL"] = sprops.Url; myRow["WebsCount"] = sprops.WebsCount; myRow["StorageUsage"] = sprops.StorageUsage; myRow["TimeZoneId"] = sprops.TimeZoneId; myRow["LastContentModifiedDate"] = sprops.LastContentModifiedDate; //THESE NO LONGER WORK //myRow["SiteCollectionURL"] = sp.Url; //myRow["WebsCount"] = sp.WebsCount; //myRow["StorageUsage"] = sp.StorageUsage; //myRow["TimeZoneId"] = sp.TimeZoneId; //myRow["LastContentModifiedDate"] = sp.LastContentModifiedDate; dtSiteStats.Rows.Add(myRow); } startIndex += spp.Count; } }
- Maria ReinbachFeb 10, 2017Copper Contributor
Thank you for confirming and for providing your code. I plan to something similar.