SharePoint CSOM Site Collection Extraction. Limited to 300?

I am trying to get a list of site collections from a SharePoint Online domain.

I am using C # and the 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 get ALL site collections using CSOM?

thank

+4
source share
2 answers

I found the answer to this question,

the first parameter of the GetSiteProperties method is the index from which the site collection search begins.

I tried the following command spp = tenant.GetSiteProperties (300, true);

which returned site collections from index 300.

So here is my code to get all site collections from sharepoint online

SPOSitePropertiesEnumerable spp = null;
var tenant = new Tenant(ctx);
int startIndex = 0;

while (spp == null || spp.Count > 0)
{
    spp = tenant.GetSiteProperties(startIndex, true);
    ctx.Load(spp);
    ctx.ExecuteQuery();

    foreach (SiteProperties sp in spp)
    siteCols.Add(new SiteCol(sp.Title, sp.Url));

    startIndex += spp.Count;
}

, 10000.

+4

, NextStartIndex , , :

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);
0

Source: https://habr.com/ru/post/1545972/


All Articles