Tuesday 4 March 2014

Create Site Collections with CSOM in SharePoint Online

With the SharePoint Conference 2014, a lot of code samples and articles where recently released. I was most impressed by the Office App Model Samples found here: http://officeams.codeplex.com/

Within that, there is some really good code of which my favorite is Creating Site Collections in SharePoint Online with CSOM. Previously this was only possible via Powershell and the SharePoint Online (SPO) Commandlets. I have modified the code provided in the samples to make it a bit less complex and you can also use it outside of an app e.g. in console applications.

You will need the following DLLs for this code to work:

The first two assemblies can be found in the ISAPI folder of your SharePoint 2013 Server Box. The Microsoft.Online.SharePoint.Client.Tenant.dll is a part of  the SharePoint Server 2013 Client Components SDK which can downloaded from here: http://www.microsoft.com/en-in/download/details.aspx?id=35585

So without much further ado, here is the code:


Geetanjali Arora said...

Great post as always :) Always some new learning when I go through your blogs mate. Keep writing good stuff.

manish singh said...

I am not able to access the online site
I have done same thing as you have shown in your code.

on clientcontx.ExecuteQuery();
I am getting the error below

An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The remote server returned an error: (407) Proxy Authentication Required.

Please let me know what the other things i have to do.

KS said...

Hello Vardhaman,
Nice article!

I wanted to create root site collection i.e. https://yoursite.sharepoint.com/

using powershell. do you know any way.
It tried different way but was it is saying that root site collection doesn't exists.

Thanks in advance!

Unknown said...


I keep getting correlation-id errors on all lists on the newly created sites. I am using the 64-bit 15 or 16 version dlls. Both versions give me the same correlation-id errors on lists. Anyone any idea what is causing this issue?

Surendra Reddy said...

Great post and very useful concept to create SharePoint site collection.

Santhosh said...


Unknown said...

How is tenant.CreateSite different from New-SPOSite powershell cmdlet?

Unknown said...

What if I wanted to use custom template to create a site collection.

Is there any way that I can upload my custom template to Central admin solution gallery

Much appreciated if you can respond.


Vardhaman Deshpande said...

Hi Ratnakumar,

To apply a custom template, you will first create a template using the PnP Schema. Then create a SPO site collection using an OOB template and then apply your PnP template to the site collection.

Hope this helps.

Unknown said...

I want to create one document library, set content search web parts on new created site collection home page. is any idea