Hi I am trying to get an app done to provision a Site Collection.
The vision is to allow the user to enter important details and then click a button and have the Site Collection created automatically.
I have had a look at the following (very excellent) posts:
but these mention that Site provisioning via the App model can only be done for Office 365.
So, I tried to modify the code of the app in Link 1, to be used within a High trust provider hosted app.
Code:
var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
using(var clientContext = spContext.CreateAppOnlyClientContextForSPHost())
{
var tenant = new Tenant(clientContext);
webUrl = String.Format("{0}{1}", BasePath, Url);
var properties = new SiteCreationProperties()
{
Url = webUrl,
Owner = sAdministrator,
Title = sTitle,
Template = sSiteTemplate,
StorageMaximumLevel = iStorageMaximum,
UserCodeMaximumLevel = dUserCodeMaximum
};
SpoOperation op = tenant.CreateSite(properties);
clientContext.Load(tenant);
clientContext.Load(op, i => i.IsComplete);
clientContext.ExecuteQuery();
//check if site creation operation is complete
while (!op.IsComplete)
{
//wait 30seconds and try again
System.Threading.Thread.Sleep(30000);
op.RefreshLoad();
clientContext.ExecuteQuery();
}
}
When executing the lines:
SpoOperation op = tenant.CreateSite(properties);
clientContext.Load(tenant);
clientContext.Load(op, i => i.IsComplete);
clientContext.ExecuteQuery();
, the following error is thrown:
Cannot find stub for type with id "{268004ae-ef6b-4e9b-8425-127220d84719}". The specified server may not support APIs used in this operation.
Any ideas what this might be caused by?
I think this is either a problem in my environmental setup, or that site collection creation can only be done for an Office 365 site?