0

I would like to create for sharepoint on premise a site collection remotely.

However, the only piece of code I found on internet is for sharepoint online https://gist.github.com/vman/9342224

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

namespace CreateSiteCollections
{
class Program
{
    static void Main(string[] args)
    {   
        //Open the Tenant Administration Context with the Tenant Admin Url
        using (ClientContext tenantContext = new ClientContext("https://yoursite-admin.sharepoint.com/"))
        {
            //Authenticate with a Tenant Administrator
            SecureString passWord = new SecureString();
            foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);
            tenantContext.Credentials = new SharePointOnlineCredentials("[email protected]", passWord);

            var tenant = new Tenant(tenantContext);

            //Properties of the New SiteCollection
            var siteCreationProperties = new SiteCreationProperties();

            //New SiteCollection Url
            siteCreationProperties.Url = "https://yoursite.sharepoint.com/sites/codesite";

            //Title of the Root Site
            siteCreationProperties.Title = "Site Created from Code";

            //Login name of Owner
            siteCreationProperties.Owner = "[email protected]";

            //Template of the Root Site. Using Team Site for now.
            siteCreationProperties.Template = "STS#0";

            //Storage Limit in MB
            siteCreationProperties.StorageMaximumLevel = 100;

            //UserCode Resource Points Allowed
            siteCreationProperties.UserCodeMaximumLevel = 50;

            //Create the SiteCollection
            SpoOperation spo = tenant.CreateSite(siteCreationProperties);

            tenantContext.Load(tenant);

            //We will need the IsComplete property to check if the provisioning of the Site Collection is complete.
            tenantContext.Load(spo, i => i.IsComplete);

            tenantContext.ExecuteQuery();

            //Check if provisioning of the SiteCollection is complete.
            while (!spo.IsComplete)
            {
                //Wait for 30 seconds and then try again
                System.Threading.Thread.Sleep(30000);
                spo.RefreshLoad();
                tenantContext.ExecuteQuery();
            }

            Console.WriteLine("SiteCollection Created.");

        }

    }
}
}

How can I tweak the above code to make it work on sharepoint 2013 et 2016

Thanks

0

1 Answer 1

0

The above code you have mentioned is a client side code and it should work with SharePoint 2013 and 2016 on premise. Only thing here is instead on onlinecredential part you need to use Network credential.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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