mercredi 25 février 2015

CSOM Iterate all SiteCollection in an SPO Tenant



I am trying to iterate over all site collections in a SharePoint Online Tenant.


I found this code on the web and adapted it to my needs:



context = SharePointContextProvider.Current.GetSharePointContext(Context);
ClientContext con = context.CreateUserClientContextForSPAppWeb();


SPOSitePropertiesEnumerable spp = null;
Microsoft.Online.SharePoint.TenantAdministration.Tenant tenant = new Tenant(con);
int startIndex = 0;

string sites = String.Empty;
while (spp == null || spp.Count > 0)
{
spp = tenant.GetSiteProperties(startIndex, true);
con.Load(spp);
con.ExecuteQuery();


foreach (SiteProperties sp in spp)
{

}
startIndex++;
}


But I keep getting the following error:



Current site is not a tenant administration site.



I am using the following library for accessing the tenants: C:\Program Files\SharePoint Client Components\Assemblies\Microsoft.Online.SharePoint.Client.Tenant.dll which has Version 15.


What am I doing wrong?








0 commentaires:

Enregistrer un commentaire