How to create a site-collection using CSOM in SharePoint Online

In this post, we’ll see how to create a site-collection using SharePoint 2013 CSOM in SharePoint Online. We’ll be using a console application for the purpose of demonstration.

Open Visual Studio 2013 –> File –> New –> Console Application and name it as ‘CreateSiteCollCSOM’.

Add references to the following assemblies





The Microsoft.Online.SharePoint.Client.Tenant.dll will be available in the location C:Program FilesSharePoint Client ComponentsAssemblies, if the SharePoint Client Components SDK is installed.

Import the following namespaces at the top of Program.cs

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

static void Main(string[] args)

            using (ClientContext oClientContext = new ClientContext(""))
                //Assign User Id for your SharePoint Online tenant     
                string UserName = "";

                //Assign password for your SharePoint online tenant
                string Password = "password";

                //Create a SecureString object from password string, needed for SharePointOnlineCredentials class
                SecureString SecurePassword = GetSecureString(Password);

                oClientContext.Credentials = new SharePointOnlineCredentials(UserName, SecurePassword);

                var oTenant = new Tenant(oClientContext);

                var oSiteCreationProperties = new SiteCreationProperties();

                //Set the url of site-collection to be created
                oSiteCreationProperties.Url = "";

                //Set the title of site
                oSiteCreationProperties.Title = "Test SiteColl from code";

                //set the site-collection owner
                oSiteCreationProperties.Owner = "";

                //set the template of site-collection to be created as TeamSite
                oSiteCreationProperties.Template = "STS#0";

                //set the storge maxium level in MB
                oSiteCreationProperties.StorageMaximumLevel = 200;

                oSiteCreationProperties.UserCodeMaximumLevel = 100;

                SpoOperation oSpoOperation = oTenant.CreateSite(oSiteCreationProperties);


                oClientContext.Load(oSpoOperation, i=>i.IsComplete);


                Console.WriteLine("SiteCollection successfully reated");



        private static SecureString GetSecureString(String Password)
            SecureString oSecurePassword = new SecureString();

            foreach (Char c in Password.ToCharArray())

            return oSecurePassword;

Leave a Reply