Tenant.CreateSite method

Queues a site collection for creation with the specified properties.

Namespace:  Microsoft.Online.SharePoint.TenantAdministration
Assembly:  Microsoft.Online.SharePoint.Client.Tenant (in Microsoft.Online.SharePoint.Client.Tenant.dll)

Syntax

'Declaration
Public Overridable Function CreateSite ( _
    siteCreationProperties As SiteCreationProperties _
) As SpoOperation
'Usage
Dim instance As Tenant
Dim siteCreationProperties As SiteCreationProperties
Dim returnValue As SpoOperation

returnValue = instance.CreateSite(siteCreationProperties)
public virtual SpoOperation CreateSite(
    SiteCreationProperties siteCreationProperties
)

Parameters

Return value

Type: Microsoft.Online.SharePoint.TenantAdministration.SpoOperation
An SpoOperation object that contains information about the site collection creation operation.

Remarks

This sample shows how to use the CreateSite method.

/// <summary>
/// Create a new site.
/// </summary>
/// <param name="targetUrl">rootsite + "/" + managedPath + "/" + sitename: e.g. "https://auto.contoso.com/sites/site1"</param>
/// <param name="title">site title: e.g. "Test Site"</param>
/// <param name="owner">site owner: e.g. admin@contoso.com</param>
/// <param name="siteTemplate">The site template used to create this new site</param>
internal void CreateSite(String targetUrl, String title, String owner, String siteTemplate)
{
    var ctx = new ClientRuntimeContext(targetUrl);
    var tenant = new Tenant(ctx);

    //Create new site
    var newsite = new SiteCreationProperties()
    {
        Url = targetUrl,
        Owner = owner,
        Template = siteTemplate,
        Title = title,
        StorageMaximumLevel = 1000,
        StorageWarningLevel = 500,
        TimeZoneId = 7,
        UserCodeMaximumLevel = 7,
        UserCodeWarningLevel = 1,
    };

    var spoOperation = tenant.CreateSite(newsite);

    ctx.Load(spoOperation);
    ctx.ExecuteQuery();

    while (!spoOperation.IsComplete)
    {
        Thread.Sleep(2000);
        ctx.Load(spoOperation);
        ctx.ExecuteQuery();
        Console.WriteLine("Site creation status: " + (spoOperation.IsComplete ? "waiting" : "complete"));
    }
}

See also

Reference

Tenant class

Tenant members

Microsoft.Online.SharePoint.TenantAdministration namespace