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:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.Online.SharePoint.Client.Tenant.dll

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:

5 comments:

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...

Hi,
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!

Marco Van Eikenhorst said...

Hi,

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?

surendrareddy said...

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