sharepointcsom

SharePoint CSOM, retrieving site collections. Limited to 300?


I am trying to retrieve the site collections list from a SharePoint Online domain.

I am using C# and client object model.

The following code returns only 300 site collections.

var tenant = new Tenant(ctx);
spp = tenant.GetSiteProperties(0, true);
ctx.Load(spp);
ctx.ExecuteQuery();

Any idea on how to retrieve ALL site collections with CSOM ?

Thanks


Solution

  • I guess NextStartIndex didn't exist at the time this was asked, nowadays you can do:

    SPOSitePropertiesEnumerable sites;
    List<string> allSites = new List<string>();
    int startIndex = 0;
    
    do
    {
        sites = tenant.GetSiteProperties(startIndex, false);
        ctx.Load(sites);
        ctx.ExecuteQuery();
    
        allSites.AddRange(sites.Select(s => s.Url));
    
        startIndex = sites.NextStartIndex;
    
    } while (sites.NextStartIndex > 0);