Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SharePoint CSOM,检索网站集。限制在300?_Sharepoint_Csom - Fatal编程技术网

SharePoint CSOM,检索网站集。限制在300?

SharePoint CSOM,检索网站集。限制在300?,sharepoint,csom,Sharepoint,Csom,我正在尝试从SharePoint Online域检索网站集列表 我正在使用C和客户机对象模型 以下代码仅返回300个网站集 var tenant = new Tenant(ctx); spp = tenant.GetSiteProperties(0, true); ctx.Load(spp); ctx.ExecuteQuery(); 你知道如何用CSOM检索所有网站集吗 谢谢我找到了这个问题的答案 GetSiteProperties方法的第一个参数是从中开始网站集检索的索引 我尝试了以下命令

我正在尝试从SharePoint Online域检索网站集列表

我正在使用C和客户机对象模型

以下代码仅返回300个网站集

var tenant = new Tenant(ctx);
spp = tenant.GetSiteProperties(0, true);
ctx.Load(spp);
ctx.ExecuteQuery();
你知道如何用CSOM检索所有网站集吗


谢谢

我找到了这个问题的答案

GetSiteProperties方法的第一个参数是从中开始网站集检索的索引

我尝试了以下命令 spp=tenant.GetSiteProperties300,true

它从索引300返回网站集

下面是我从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个。

我想在询问此问题时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);

我认为可能需要做一点小小的改进:startIndex+=spp.Count,而不是您要添加到的集合。感谢Mikael,我做了一个警告:如果您使用GetSiteProperties ByFilter而不是GetSiteProperties,这可能无法按预期工作。