Last active
August 12, 2018 09:46
-
-
Save AsishP/388af1e2dab5aed6a55b173dba64254d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Online.SharePoint.TenantAdministration; | |
using Microsoft.SharePoint.Client; | |
using OfficeDevPnP.Core.Sites; | |
using (ClientContext ctx = new ClientContext(<TenantAdminUrl>)) | |
{ | |
// create new "modern" team site at the url | |
// https://[tenant].sharepoint.com/sites/mymodernteamsite | |
string alias = taskParam.TargetWebUrl.Substring(Url.LastIndexOf('/') + 1); | |
// Before creating let's make sure the site doesn't exist | |
bool exists = false; | |
Task existtask = Task.Run(async () => exists = await ctx.AliasExistsAsync(alias)); | |
existtask.Wait(); | |
if (!exists) | |
{ | |
log.Info("Creating site with a new Async method"); | |
TeamSiteCollectionCreationInformation teamSiteCreation = new TeamSiteCollectionCreationInformation(); | |
// Provide the team site para | |
teamSiteCreation.Alias = <GroupAlias>; | |
teamSiteCreation.DisplayName = <WebTitle>; | |
teamSiteCreation.IsPublic = <true or false>; | |
teamSiteCreation.Description = <Description>; | |
ClientContext teamcontext = ctx.CreateSiteAsync(teamSiteCreation).GetAwaiter().GetResult(); | |
teamcontext.Load(teamcontext.Web, w => w.Lists, w => w.Url); | |
teamcontext.ExecuteQueryRetry(); | |
//Call the Ensure Site Assets Library method to initialize the Site Assets library | |
teamcontext.Web.Lists.EnsureSiteAssetsLibrary(); | |
teamcontext.ExecuteQueryRetry(); | |
log.Info("The site has been successfully created at: " + teamcontext.Web.Url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment