Skip to content

Instantly share code, notes, and snippets.

@dgusoff
Created October 13, 2015 19:46
Show Gist options
  • Save dgusoff/bd9005d4826fe84089c0 to your computer and use it in GitHub Desktop.
Save dgusoff/bd9005d4826fe84089c0 to your computer and use it in GitHub Desktop.
Create new Site Colleciton
public static void CreateSiteCollection(ClientContext adminContext, string url, string template, string title, string description, int storageLevel, string owner, bool wait)
{
var tenant = new Tenant(adminContext);
var properties = new SiteCreationProperties()
{
Url = url,
Owner = owner,
Title = title,
Template = template,
StorageMaximumLevel = storageLevel,
UserCodeMaximumLevel = 0
};
//start the SPO operation to create the site
SpoOperation op = tenant.CreateSite(properties);
adminContext.Load(tenant);
adminContext.Load(op, i => i.IsComplete);
adminContext.ExecuteQuery();
//check if site creation operation is complete
if (wait)
{
while (!op.IsComplete)
{
Console.WriteLine("Waiting for site at {0}", url);
//wait 30seconds and try again
System.Threading.Thread.Sleep(30000);
op.RefreshLoad();
adminContext.ExecuteQuery();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment