Get list of site collections using CSOM in Office365

Posted on 4/28/2014 @ 7:28 AM in #SharePoint by | Feedback | 5250 views

Title says it all, here is how -

   1:  var token = TokenHelper.GetAppOnlyAccessToken("00000003-0000-0ff1-ce00-000000000000", 
   2:      tenantAdminUri.Authority, null).AccessToken;
   3:  using (var clientContext = TokenHelper.GetClientContextWithAccessToken("https://yourtenant-admin.sharepoint.com", token))
   4:  {
   5:      var tenant = new Tenant(clientContext);
   6:      SPOSitePropertiesEnumerable spp = tenant.GetSiteProperties(0, true);
   7:      clientContext.Load(spp);
   8:      clientContext.ExecuteQuery();
   9:      foreach(SiteProperties sp in spp)
  10:      {
  11:          // you'll get your site collections here
  12:      }
  13:  }

Sound off but keep it civil:

Older comments..