SharePoint CSOM, retrieving site collections. Limited to 300?

对着背影说爱祢 提交于 2019-12-04 10:08:13

I found the answer to this question,

the first parameter of the method GetSiteProperties is the index from which site collection retrieval starts.

I tried the 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;
}

By the way, site collections are currently limited to 10000.

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!