pnp/PnP

Unable to provision modern site using provider hosted app in SharePoint 2019

anomepani opened this issue · 0 comments

We are trying to create a modern site from the provider hosted app in SharePoint 2019.
We have tried creating a modern site using SharePoint in-built(team "STS#3" and communication "SITEPAGEPUBLISHING#0") site collection template, but it creates a classic site. Also, we have tried creating classic team/communication site and added a modern page in that and saved that site as a template. Taking base as that template, we tried creating a modern site, but here also it creates a classic site only.

Category

[x] Bug
[ ] Enhancement

Environment

[ ] Office 365 / SharePoint Online
[x] SharePoint 2019
[ ] SharePoint 2016
[ ] SharePoint 2013

If SharePoint on-premises, what's exact CU version:

Expected or Desired Behavior

We have tried creating a modern site using SharePoint in-built(team "STS#3" and communication "SITEPAGEPUBLISHING#0") site collection template, It should create a modern site.

Observed Behavior

We have tried creating a modern site using SharePoint in-built(team "STS#3" and communication "SITEPAGEPUBLISHING#0") site collection template, but it creates a classic site.

Steps to Reproduce

We are using the below project Reference link for creating this app: https://github.com/SharePoint/PnP/tree/master/Samples/Provisioning.SiteCol.OnPrem

Source code for the code snippet
 private string CreateSiteCollection(string hostWebUrl, string url, string template, string title, string adminAccount)
        {
            // Resolve root site collection URL from host web. We assume that this has been set as the "TenantAdminSite"
            string rootSiteUrl = hostWebUrl.Substring(0, 8 + hostWebUrl.Substring(8).IndexOf("/"));

            //Resolve URL for the new site collection
            var webUrl = string.Format("{0}/sites/{1}", rootSiteUrl, url);

            // Notice that this assumes that AdministrationSiteType as been set as TenantAdministration for root site collection
            // If this tenant admin URI is pointing to site collection which is host named site collection, code does create host named site collection as well
            var tenantAdminUri = new Uri(rootSiteUrl);
            string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
            var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, realm).AccessToken;
            using (var adminContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
            {
                var tenant = new Tenant(adminContext);
                var properties = new SiteCreationProperties()
                {
                    Url = webUrl,
                    Owner = adminAccount,
                    Title = title,
                    Template = template
                };

                //start the SPO operation to create the site
                SpoOperation op = tenant.CreateSite(properties);
                adminContext.Load(op, i => i.IsComplete);
                adminContext.ExecuteQuery();
            }

            // Set theme for the new site
            SetThemeToNewSite(webUrl);

            // Return URL for redirection
            return webUrl;
        }