SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been trying out to create site collection using CSOM but unable to fins and class which creates site collection.

I have read in MSDN that CSOM runs as site collection scope hence creating site collection permission is not available.

Sub-Site i am able to create properly but unable to create site collection.

share|improve this question

This example is taken from a SharePoint Online environment with provided hosted apps in mind. Creating a console application, adding reference to

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll
  • Microsoft.Online.SharePoint.Client.Tenant.dll

and pasting this snippet to the main method should do the trick.

var SHAREPOINT_PID = "00000003-0000-0ff1-ce00-000000000000"; // SharePoint constant
var tenantAdminUri = new Uri("https://<TENANT>");
var token = TokenHelper.GetAppOnlyAccessToken(SHAREPOINT_PID, tenantAdminUri.Authority, null).AccessToken;

using (var context = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
    var tenant = new Tenant(context);
    var properties = new SiteCreationProperties()
        Url = "https://<TENANT>",
        Owner = "<USER>@<TENANT>",
        Template = "STS#0",
        StorageMaximumLevel = 1000,
        UserCodeMaximumLevel = 300


In this example I’ve created a simple console application but it might as well be a service running in Azure or any other .NET application.

Reference: Create Site Collections in SharePoint Online using CSOM

share|improve this answer

Tenant.CreateSite method queues a site collection for creation with the specified properties. Tenant class is a part of Microsoft.Online.SharePoint.Client.Tenant.dll (SharePoint Online Management Shell)

How to create site collection via CSOM in SharePoint 2013

using System;
using System.Security;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;

namespace CSOMProvisioning
    class Program
        static void Main(string[] args)

            const string username = "";
            const string password = "password";
            const string tenantAdminUrl = "";
            var securedPassword = new SecureString();
            foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
            var credentials = new SharePointOnlineCredentials(username, securedPassword);

            using (var context = new ClientContext(tenantAdminUrl))
                context.Credentials = credentials;
                CreateSite(context, "","Marketing");


        /// <summary>
        /// Create a new site.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="url">rootsite + "/" + managedPath + "/" + sitename: e.g. ""</param>
        /// <param name="title">site title: e.g. "Test Site"</param>
        /// <param name="owner">site owner: e.g.</param>
        /// <param name="template">The site template used to create this new site</param>
        /// <param name="localeId"></param>
        /// <param name="compatibilityLevel"></param>
        /// <param name="storageQuota"></param>
        /// <param name="resourceQuota"></param>
        /// <param name="timeZoneId"></param>
        internal static void CreateSite(ClientContext context, String url, String owner, String title =null, String template = null, uint? localeId = null, int? compatibilityLevel = null, long? storageQuota = null, double? resourceQuota = null, int? timeZoneId = null)
            var tenant = new Tenant(context);

            if (url == null)
                throw new ArgumentException("Site Url must be specified");

            if (string.IsNullOrEmpty(owner))
                throw new ArgumentException("Site Owner must be specified");

            var siteCreationProperties = new SiteCreationProperties {Url = url, Owner = owner};
            if (!string.IsNullOrEmpty(template))
                siteCreationProperties.Template = template;
            if (!string.IsNullOrEmpty(title))
                siteCreationProperties.Title = title;
            if (localeId.HasValue)
                siteCreationProperties.Lcid = localeId.Value;
            if (compatibilityLevel.HasValue)
                siteCreationProperties.CompatibilityLevel = compatibilityLevel.Value;
            if (storageQuota.HasValue)
                siteCreationProperties.StorageMaximumLevel = storageQuota.Value;
            if (resourceQuota.HasValue)
                siteCreationProperties.UserCodeMaximumLevel = resourceQuota.Value;
            if (timeZoneId.HasValue)
                siteCreationProperties.TimeZoneId = timeZoneId.Value;
            var siteOp = tenant.CreateSite(siteCreationProperties);


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.