Forum Discussion

Prasham_Sabadra's avatar
Prasham_Sabadra
Copper Contributor
Nov 11, 2019

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

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

  • Prasham_Sabadra's avatar
    Prasham_Sabadra
    Copper Contributor

    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 🙂

    • Preeti1910's avatar
      Preeti1910
      Icon for Microsoft rankMicrosoft

      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.

  • HelloPrasham_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

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

Resources