How to associate Hub site to the site created without Office 365 Group using CSOM

Copper Contributor

Hi All,

 

We are creating site without Office 365 group using CSOM. But couldnt find the way to associate the hub site to our newly created site.

 

Any reference / idea will be highly appreciated.  

 

Thanks.

Br,

Prasham

5 Replies
This is something you can easily achieve by means of a PnP template where you have the Hub association

@Juan Carlos González Martín Thanks for the reply. Is it possible to share some sample code?

 

Hello@Prasham Sabadra !

If I understand you correctly, you have a Hub site in SharePoint Online. 
and you want to associate a non-Office365 group connected SharePoint site to that hub? 

How did you create that site and what template does it use? 

Kind Regards
Oliwer Sjöberg

I could resolve this issue.

 

Details:

We are creating Modern Team site without Office 365 group using CSOM. Using Tenant.CreateSite() method as

 

var tenant = new Tenant(tenantContext);
var spo = tenant.CreateSite(siteCreationProperties);

 

And then used the Tenant.ConnectSiteToHubSite() method to connect it to Hub site as

//Associating new site to Hub site
tenant.ConnectSiteToHubSite(siteUrl, HubsiteURL);
ccTennant.ExecuteQuery();

 

It seems to be working fine for me now.

 

Thanks all for replying and helping :)

@Prasham Sabadra 

 

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?

 

here in the line

var tenant = new Tenant(tenantContext);

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