Saturday 31 March 2018

Working with SharePoint Online Hub sites using CSOM

With SharePoint Online Hub sites launched for Targeted release tenants, here is some quick code I put together to work with them using CSOM:

1) Register a Hub site, Connect a site to a Hub site, Disconnect a site from a Hub site and Unregister a Hub site:

2) Grant and Revoke specific users rights to connect sites to a Hub site:

When a Hub site is registered, it is public by default. Any user is able to connect their site to the hub site. If you want only a specific set of users to be able to connect their site to the Hub site, you can grant "Join" rights to these users:

Hope this helps!

1 comment:

Preeti Teotia said...

If I am associating a SPO site with hubsite with multigeo scenario means SPO site and hubsite are at different geolocation, then tenantContext will be used of which? site or hubsite

var clientContext = GetClientContext(adminSiteUrl);

var tenant = new Tenant(clientContext);
tenant.ConnectSiteToHubSite(siteUrl, hubSiteUrl);

Here , while creating clientContext, which adminSiteUrl will be passed? it should be of hubsite or SPO site to be associated.