Jul 18 2019 11:07 PM
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.
[x] SharePoint 2019
Build Name: SharePoint Server 2019 RTM
CU Version: 16.0.10337.12109
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.
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.
We are using the below project Reference link for creating this app: https://github.com/SharePoint/PnP/tree/master/Samples/Provisioning.SiteCol.OnPrem
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;
}
Jul 19 2019 12:25 AM - edited Jul 19 2019 01:58 AM
@ArvindKumar Mepaniwhat version of Microsoft.Online.SharePoint.Client.Tenant.dll are you referencing in your project?
I've just created a simple Console Application to see if I was able to create both a modern team site and a communication site collection in my environment and it gives me the modern sites as expected. I'm basically using the same code as yours except that I don't call SetThemeToNewSite in the end. Could it be this method is causing your site to revert back to classic experience somehow?
I'm using version 16.1.9021.1200 (latest version of Microsoft.SharePointOnline.CSOM NuGet package).
Jul 22 2019 03:43 AM
Thanks for your help, @Paul Pascha
The version of Microsoft.Online.SharePoint.Client.Tenant.dll is 16.1.9021.1200.
I am also able to create a modern site collection using a console app. But when I tried creating modern site collection with the same code using provider hosted app, it always creates classic site only.
I have removed SetThemeToNewSite method as well.
Jul 22 2019 11:48 PM
Jul 23 2019 04:17 AM
Hi @Paul Pascha ,
We have updated the CU version (May 2019 CU) but still we are not able to create modern site collection using provider hosted app.
Note: we are not using App only authentication. We have added GetS2SAccessTokenWithWindowsIdentity for the authentication as per our requirement.
We are using following code snippet is for authentication:
TokenHelper.GetS2SAccessTokenWithWindowsIdentity(tenantAdminUri, HttpContext.Current.User.Identity as WindowsIdentity);
Jul 23 2019 11:30 PM
Dec 03 2020 07:36 AM
@Paul Pascha Hello, can you please tell me if provider hosted app can be created using modern team or communication sites?
Also, can we select ASP.Net MVC from visual studio ?