Get list of site collections using CSOM in Office365

Recently, while working on a SharePoint Online project for a client, came across a requirement to create a consolidated report from all site collections i.e. we need to access or get list of all site collections. Below code helps to get that:-

var token = TokenHelper.GetAppOnlyAccessToken(“00000003-0000-0ff1-ce00-000000000000”, tenantAdminUri.Authority, null).AccessToken;
using (var clientContext = TokenHelper.GetClientContextWithAccessToken(“”, token))
var tenant = new Tenant(clientContext);
SPOSitePropertiesEnumerable spp = tenant.GetSiteProperties(0, true);
foreach(SiteProperties sp in spp)
// you’ll get your site collections here


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s