本文整理汇总了C#中Tenant.CreateSite方法的典型用法代码示例。如果您正苦于以下问题:C# Tenant.CreateSite方法的具体用法?C# Tenant.CreateSite怎么用?C# Tenant.CreateSite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tenant
的用法示例。
在下文中一共展示了Tenant.CreateSite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
string SHAREPOINT_PID = "00000003-0000-0ff1-ce00-000000000000"; //This is hard-coded for SharePoint Online (ie - all tenants)
//The app must have tenant-level permissions and can be installed on any site in the tenancy. You must use the tenant
//admin site url to get client context.
var sharePointUrl = new Uri("https://<Office 365 domain>-admin.sharepoint.com");
string sharePointRealm = TokenHelper.GetRealmFromTargetUrl(sharePointUrl);
var token = TokenHelper.GetAppOnlyAccessToken(SHAREPOINT_PID, sharePointUrl.Authority, sharePointRealm).AccessToken;
//read the Sites.xml file and then release the file so we can save over it later
string path = @"C:\<path>\Sites.xml";
XDocument doc;
using (var fileStream = System.IO.File.OpenRead(path))
{
doc = XDocument.Load(fileStream);
}
//get all the requested sites from the Sites.xml file and loop through each for processing
var sites = doc.Root.Elements("site");
foreach (var site in sites)
{
using (var clientContext = TokenHelper.GetClientContextWithAccessToken(sharePointUrl.ToString(), token))
{
clientContext.Load(clientContext.Web.Lists);
clientContext.ExecuteQuery();
var siteUrl = site.Attribute("url").Value;
var tenant = new Tenant(clientContext);
var newSite = new SiteCreationProperties()
{
Url = siteUrl,
Owner = "<admin user>@<Office 365 domain>.onmicrosoft.com",
Template = "STS#0",
Title = "Batch provisioning test site",
//StorageMaximumLevel = 100,
//StorageWarningLevel = 300,
TimeZoneId = 7,
UserCodeMaximumLevel = 7,
UserCodeWarningLevel = 1,
};
var spoOperation = tenant.CreateSite(newSite);
clientContext.Load(spoOperation);
clientContext.ExecuteQuery();
while (!spoOperation.IsComplete)
{
System.Threading.Thread.Sleep(2000);
clientContext.Load(spoOperation);
clientContext.ExecuteQuery();
}
}
}
}
示例2: CreateSiteCollectionFromTemplate
private static void CreateSiteCollectionFromTemplate(ClientContext cc, string tenantUrl, string newSiteUrl, string userName)
{
Tenant tenant = new Tenant(cc);
SiteCreationProperties newsiteProp = new SiteCreationProperties();
newsiteProp.Lcid = 1033;
newsiteProp.Owner = userName;
newsiteProp.Title = "New Site";
newsiteProp.Url = newSiteUrl;
newsiteProp.StorageMaximumLevel = 100; //MB
newsiteProp.UserCodeMaximumLevel = 10;
SpoOperation spoO = tenant.CreateSite(newsiteProp);
cc.Load(spoO, i => i.IsComplete);
cc.ExecuteQuery();
while (!spoO.IsComplete)
{
//Wait for 30 seconds and then try again
System.Threading.Thread.Sleep(10000);
spoO.RefreshLoad();
cc.ExecuteQuery();
Console.WriteLine("Site creation status: " + (spoO.IsComplete ? "completed" : "waiting"));
}
Console.WriteLine("SiteCollection Created.");
}
示例3: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
Uri tenantAdministrationUrl = new Uri("https://dotnetrocks-admin.sharepoint.com/");
string accessToken = TokenHelper.GetAppOnlyAccessToken(
TokenHelper.SharePointPrincipal,
tenantAdministrationUrl.Authority,
TokenHelper.GetRealmFromTargetUrl(tenantAdministrationUrl)).AccessToken;
var newSite = new SiteCreationProperties()
{
Url = "https://dotnetrocks.sharepoint.com/sites/" + SiteName.Text,
Owner = SiteOwner.Text,
Template = "STS#0", // Team Site
Title = "App Provisioned Site - " + SiteName.Text,
StorageMaximumLevel = 1000,
StorageWarningLevel = 500,
TimeZoneId = 7,
UserCodeMaximumLevel = 7,
UserCodeWarningLevel = 1
};
using (var clientContext = TokenHelper.GetClientContextWithAccessToken(tenantAdministrationUrl.ToString(), accessToken))
{
var tenant = new Tenant(clientContext);
var spoOperation = tenant.CreateSite(newSite);
clientContext.Load(spoOperation);
clientContext.ExecuteQuery();
}
}
示例4: CreateSiteCollection
public override void CreateSiteCollection(SiteInformation siteRequest, Template template)
{
Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
UsingContext(ctx =>
{
try
{
Stopwatch _timespan = Stopwatch.StartNew();
Tenant _tenant = new Tenant(ctx);
var _newsite = new SiteCreationProperties();
_newsite.Title = siteRequest.Title;
_newsite.Url = siteRequest.Url;
_newsite.Owner = siteRequest.SiteOwner.Name;
_newsite.Template = template.RootTemplate;
_newsite.Lcid = siteRequest.Lcid;
_newsite.TimeZoneId = siteRequest.TimeZoneId;
_newsite.StorageMaximumLevel = template.StorageMaximumLevel;
_newsite.StorageWarningLevel = template.StorageWarningLevel;
_newsite.UserCodeMaximumLevel = template.UserCodeMaximumLevel;
_newsite.UserCodeMaximumLevel = template.UserCodeWarningLevel;
SpoOperation op = _tenant.CreateSite(_newsite);
ctx.Load(_tenant);
ctx.Load(op, i => i.IsComplete);
ctx.ExecuteQuery();
while (!op.IsComplete)
{
//wait 30seconds and try again
System.Threading.Thread.Sleep(30000);
op.RefreshLoad();
ctx.ExecuteQuery();
}
var _site = _tenant.GetSiteByUrl(siteRequest.Url);
var _web = _site.RootWeb;
_web.Description = siteRequest.Description;
_web.Update();
ctx.Load(_web);
ctx.ExecuteQuery();
_timespan.Stop();
Log.TraceApi("SharePoint", "Office365SiteProvisioningService.CreateSiteCollection", _timespan.Elapsed, "SiteUrl={0}", siteRequest.Url);
}
catch (Exception ex)
{
Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
PCResources.SiteCreation_Creation_Failure,
siteRequest.Url, ex.Message, ex);
throw;
}
Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Successful, siteRequest.Url);
});
}
示例5: CreateSiteCollection
public static string CreateSiteCollection(ClientContext ctx, string hostWebUrl, string template, string title, string description, string userEmail)
{
//get the base tenant admin urls
var tenantStr = hostWebUrl.ToLower().Replace("-my", "").Substring(8);
tenantStr = tenantStr.Substring(0, tenantStr.IndexOf("."));
//create site collection using the Tenant object
var webUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", tenantStr, "sites", title);
var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantStr));
string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, realm).AccessToken;
using (var adminContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
{
var tenant = new Tenant(adminContext);
var properties = new SiteCreationProperties()
{
Url = webUrl,
Owner = userEmail,
Title = title,
Template = template,
StorageMaximumLevel = 100,
UserCodeMaximumLevel = 100
};
//start the SPO operation to create the site
SpoOperation op = tenant.CreateSite(properties);
adminContext.Load(tenant);
adminContext.Load(op, i => i.IsComplete);
adminContext.ExecuteQuery();
//check if site creation operation is complete
while (!op.IsComplete)
{
//wait 30seconds and try again
System.Threading.Thread.Sleep(30000);
op.RefreshLoad();
adminContext.ExecuteQuery();
}
}
//get the new site collection
var siteUri = new Uri(webUrl);
token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;
using (var newWebContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), token))
{
var newWeb = newWebContext.Web;
newWebContext.Load(newWeb);
newWebContext.ExecuteQuery();
new LabHelper().SetThemeBasedOnName(newWebContext, newWeb, newWeb, "Orange");
// All done, let's return the newly created site
return newWeb.Url;
}
}
示例6: ProcessOneWayEvent
public void ProcessOneWayEvent(SPRemoteEventProperties properties)
{
string SHAREPOINT_PID = "00000003-0000-0ff1-ce00-000000000000"; //This is hard-coded for SharePoint Online (ie - all tenants)
//The app must have tenant-level permissions and can be installed on any site in the tenancy. You must use the tenant
//admin site url to get client context.
Uri sharePointUrl = new Uri("https://<your-domain>-admin.sharepoint.com");
string myRealm = TokenHelper.GetRealmFromTargetUrl(sharePointUrl);
try
{
string accessToken = TokenHelper.GetAppOnlyAccessToken(SHAREPOINT_PID, sharePointUrl.Authority, myRealm).AccessToken;
using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(sharePointUrl.ToString(), accessToken))
{
if (clientContext != null)
{
var requestTitle = properties.ItemEventProperties.AfterProperties["Title"];
var tenant = new Tenant(clientContext);
var newSite = new SiteCreationProperties()
{
Url = "https://<your domain>.sharepoint.com/sites/" + requestTitle,
Owner = "[email protected]<your domain>.onmicrosoft.com",
Template = "STS#0",
Title = "Workflow provisioning test site two",
StorageMaximumLevel = 1000,
StorageWarningLevel = 500,
TimeZoneId = 7,
UserCodeMaximumLevel = 7,
UserCodeWarningLevel = 1,
};
var spoOperation = tenant.CreateSite(newSite);
clientContext.Load(spoOperation);
clientContext.ExecuteQuery();
while (!spoOperation.IsComplete)
{
System.Threading.Thread.Sleep(2000);
clientContext.Load(spoOperation);
clientContext.ExecuteQuery();
}
}
}
}
catch (Exception ex)
{
var exception = ex;
}
}
示例7: CreateNewSiteCollection
private void CreateNewSiteCollection(object modelHost, ClientContext context, O365SiteDefinition o365SiteModel)
{
var tenant = new Tenant(context);
var siteCollectionProperties = MapSiteCollectionProperties(o365SiteModel);
tenant.CreateSite(siteCollectionProperties);
context.Load(tenant);
context.ExecuteQuery();
// from here site collection is being provisioned by O365 asynchronously
// we need to have sorta delay with querying new site collection and continue deployment flow once it has been fully provisioned
var siteCreated = WaitForSiteProvision(context, o365SiteModel.Url);
if (siteCreated)
{
WithExistingSiteAndWeb(context, o365SiteModel.Url, (site, web) =>
{
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = site,
ObjectType = typeof(Site),
ObjectDefinition = o365SiteModel,
ModelHost = modelHost
});
});
}
else
{
// probably, we should throw an exception as site was not created
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = null,
ObjectType = typeof(Site),
ObjectDefinition = o365SiteModel,
ModelHost = modelHost
});
}
}
示例8: Execute
public void Execute(ClientContext ctx, Uri url, string template, string owner, string title, int sizeInMb, uint languageId)
{
Logger.Verbose($"Started executing {nameof(CreateSiteCollection)} for url '{url}'");
var tenant = new Tenant(ctx);
ctx.Load(tenant);
var siteCollections = tenant.GetSiteProperties(0, true);
ctx.Load(siteCollections);
ctx.ExecuteQuery();
var siteCollection = siteCollections.SingleOrDefault(sc => sc.Url == url.ToString());
if (siteCollection != null)
{
Logger.Warning($"Site collection at url '{url}' already exist");
return;
}
var operation = tenant.CreateSite(new SiteCreationProperties
{
Url = url.ToString(),
Owner = owner,
Template = template,
StorageMaximumLevel = sizeInMb,
UserCodeMaximumLevel = 0,
UserCodeWarningLevel = 0,
// level is in absolute MBs, not percent
StorageWarningLevel = (long)(sizeInMb * 0.9),
Title = title,
CompatibilityLevel = 15,
TimeZoneId = 3,
Lcid = languageId
});
ctx.Load(operation);
ctx.ExecuteQuery();
while (!operation.IsComplete)
{
System.Threading.Thread.Sleep(15000);
ctx.Load(operation);
ctx.ExecuteQuery();
var status = operation.IsComplete ? "complete" : "waiting";
Logger.Verbose($"Site creation status: {status}");
}
}
示例9: ProcessCloudRequest
/// <summary>
/// Ccloud request processing. Based on following project:
/// This should be located in cloud specific buisness logic component, but added here for simplicity reasons.
/// </summary>
/// <param name="request"></param>
/// <param name="log"></param>
private static void ProcessCloudRequest(SiteCollectionRequest request, TextWriter log)
{
//get the base tenant admin urls
string tenantStr = ConfigurationManager.AppSettings["Office365Tenant"];
//create site collection using the Tenant object
var webUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", tenantStr, "sites", Guid.NewGuid().ToString().Replace("-", ""));
var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantStr));
// Connecting to items using app only token
string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, realm).AccessToken;
using (var adminContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
{
var tenant = new Tenant(adminContext);
var properties = new SiteCreationProperties()
{
Url = webUrl,
Owner = request.OwnerIdentifier,
Title = request.Title,
Template = "STS#0", // Create always team site and specialize after site collection is created as needed
StorageMaximumLevel = 100,
UserCodeMaximumLevel = 100
};
//start the SPO operation to create the site
SpoOperation op = tenant.CreateSite(properties);
adminContext.Load(tenant);
adminContext.Load(op, i => i.IsComplete);
adminContext.ExecuteQuery();
//check if site creation operation is complete
while (!op.IsComplete)
{
//wait 15 seconds and try again
System.Threading.Thread.Sleep(15000);
op.RefreshLoad();
adminContext.ExecuteQuery();
}
}
log.WriteLine(String.Format("Create new site collection with URL '{1}' at {0}", webUrl, DateTime.Now.ToLongTimeString()));
ApplyTemplateForCreatedSiteCollection(webUrl, token, realm);
log.WriteLine(String.Format("Applied custom branding to new site collection with URL '{1}' at {0}", webUrl, DateTime.Now.ToLongTimeString()));
}
示例10: ProcessSiteCreationRequest
public string ProcessSiteCreationRequest(ClientContext adminCtx, ProvisioningData provisionData)
{
// Create the site collection
//get the base tenant administration urls
var webFullUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", provisionData.TenantName, "sites", provisionData.RequestData.Url);
var tenant = new Tenant(adminCtx);
var properties = new SiteCreationProperties()
{
Url = webFullUrl,
Owner = provisionData.RequestData.Owner,
Title = provisionData.RequestData.Title,
Template = provisionData.RequestData.Template,
TimeZoneId = provisionData.RequestData.TimeZoneId,
Lcid = provisionData.RequestData.Lcid,
StorageMaximumLevel = provisionData.RequestData.StorageMaximumLevel
};
//start the SPO operation to create the site
SpoOperation op = tenant.CreateSite(properties);
adminCtx.Load(tenant);
adminCtx.Load(op, i => i.IsComplete);
adminCtx.ExecuteQuery();
//check if site creation operation is complete
while (!op.IsComplete)
{
//wait 15 seconds and try again
System.Threading.Thread.Sleep(15000);
op.RefreshLoad();
adminCtx.ExecuteQuery();
}
// Apply branding if theme information is provided
if (!string.IsNullOrEmpty(provisionData.BrandingData.ThemeName))
{
ApplyTemplateForCreatedSiteCollection(webFullUrl, provisionData);
}
return webFullUrl;
}
示例11: DeployModel
public override void DeployModel(object modelHost, DefinitionBase model)
{
var siteModelHost = modelHost.WithAssertAndCast<SiteModelHost>("modelHost", value => value.RequireNotNull());
//var siteModel = model.WithAssertAndCast<SiteDefinition>("model", value => value.RequireNotNull());
var context = siteModelHost.HostClientContext;
var tenant = new Tenant(context);
var properties = new SiteCreationProperties()
{
Url = "https://<TENANT>.sharepoint.com/sites/site1",
Owner = "<USER>@<TENANT>.onmicrosoft.com",
Template = "STS#0",
StorageMaximumLevel = 1000,
UserCodeMaximumLevel = 300
};
tenant.CreateSite(properties);
context.Load(tenant);
context.ExecuteQuery();
}
示例12: CreateSiteCollection
/// <summary>
///
/// </summary>
/// <param name="hostWebUrl"></param>
/// <param name="txtUrl"></param>
/// <param name="template"></param>
/// <param name="title"></param>
/// <param name="description"></param>
/// <param name="cc"></param>
/// <param name="page"></param>
/// <param name="baseConfiguration"></param>
/// <returns></returns>
public Web CreateSiteCollection(string hostWebUrl, string txtUrl, string template, string title, string description,
Microsoft.SharePoint.Client.ClientContext cc, Page page, XDocument baseConfiguration)
{
//get the template element
XElement templateConfig = GetTemplateConfig(template, baseConfiguration);
string siteTemplate = SolveUsedTemplate(template, templateConfig);
//get the base tenant admin urls
var tenantStr = hostWebUrl.ToLower().Replace("-my", "").Substring(8);
tenantStr = tenantStr.Substring(0, tenantStr.IndexOf("."));
//get the current user to set as owner
var currUser = cc.Web.CurrentUser;
cc.Load(currUser);
cc.ExecuteQuery();
//create site collection using the Tenant object
var webUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", tenantStr, templateConfig.Attribute("ManagedPath").Value, txtUrl);
var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantStr));
string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, realm).AccessToken;
using (var adminContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
{
var tenant = new Tenant(adminContext);
var properties = new SiteCreationProperties()
{
Url = webUrl,
Owner = currUser.Email,
Title = title,
Template = siteTemplate,
StorageMaximumLevel = Convert.ToInt32(templateConfig.Attribute("StorageMaximumLevel").Value),
UserCodeMaximumLevel = Convert.ToDouble(templateConfig.Attribute("UserCodeMaximumLevel").Value)
};
//start the SPO operation to create the site
SpoOperation op = tenant.CreateSite(properties);
adminContext.Load(tenant);
adminContext.Load(op, i => i.IsComplete);
adminContext.ExecuteQuery();
//check if site creation operation is complete
while (!op.IsComplete)
{
//wait 30seconds and try again
System.Threading.Thread.Sleep(30000);
op.RefreshLoad();
adminContext.ExecuteQuery();
}
}
//get the new site collection
var siteUri = new Uri(webUrl);
token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;
using (var newWebContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), token))
{
var newWeb = newWebContext.Web;
newWebContext.Load(newWeb);
newWebContext.ExecuteQuery();
//process the remiander of the template configuration
DeployFiles(newWebContext, newWeb, templateConfig);
DeployCustomActions(newWebContext, newWeb, templateConfig);
DeployLists(newWebContext, newWeb, templateConfig);
DeployNavigation(newWebContext, newWeb, templateConfig);
DeployTheme(newWebContext, newWeb, templateConfig, baseConfiguration);
SetSiteLogo(newWebContext, newWeb, templateConfig);
// All done, let's return the newly created site
return newWeb;
}
}
示例13: ProcessSiteCreationRequest
/// <summary>
/// Actual business logic to create the site collections.
/// See more details on the requirements for on-premises from following blog post:
/// http://blogs.msdn.com/b/vesku/archive/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom.aspx
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
private static string ProcessSiteCreationRequest(SiteCollectionRequest request)
{
// Get the base tenant admin url needed for site collection creation
string tenantStr = ConfigurationManager.AppSettings[Consts.AdminSiteCollectionUrl];
// Resolve root site collection URL from host web.
string rootSiteUrl = ConfigurationManager.AppSettings[Consts.LeadingURLForSiteCollections];
// Create unique URL based on GUID. In real production implementation you might do this otherways, but this is for simplicity purposes
var webUrl = string.Format("{0}/sites/{1}", rootSiteUrl, Guid.NewGuid().ToString().Replace("-", ""));
var tenantAdminUri = ConfigurationManager.AppSettings[Consts.AdminSiteCollectionUrl];
// Notice that we do NOT use app model where for this sample. We use just specific service account. Could be easily
// changed for example based on following sample: https://github.com/OfficeDev/PnP/tree/master/Samples/Provisioning.OnPrem.Async
using (var ctx = new ClientContext(tenantAdminUri))
{
ctx.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings[Consts.ProvisioningAccount],
ConfigurationManager.AppSettings[Consts.ProvisioningPassword],
ConfigurationManager.AppSettings[Consts.ProvisioningDomain]);
// Set the time out as high as possible
ctx.RequestTimeout = Timeout.Infinite;
var tenant = new Tenant(ctx);
var properties = new SiteCreationProperties()
{
Url = webUrl,
Owner = string.Format("{0}\\{1}",
ConfigurationManager.AppSettings[Consts.ProvisioningDomain],
ConfigurationManager.AppSettings[Consts.ProvisioningAccount]),
Title = request.Title,
Template = "STS#0" // Create always team site, but specialize the site based on the template value
};
//start the SPO operation to create the site
SpoOperation op = tenant.CreateSite(properties);
ctx.Load(op, i => i.IsComplete);
ctx.ExecuteQuery();
}
// Do some branding for the new site
SetThemeToNewSite(webUrl);
// Do addditional customziations based on the selected template request.Template
return webUrl;
}
示例14: ProcessSiteCreationRequest
private static string ProcessSiteCreationRequest(ClientContext ctx, ListItem listItem)
{
//get the base tenant admin urls
string tenantStr = ConfigurationManager.AppSettings["SiteCollectionRequests_SiteUrl"];
// Resolve root site collection URL from host web. We assume that this has been set as the "TenantAdminSite"
string rootSiteUrl = tenantStr.Substring(0, 8 + tenantStr.Substring(8).IndexOf("/"));
//Resolve URL for the new site collection
var webUrl = string.Format("{0}/sites/{1}", rootSiteUrl, listItem["SiteUrl"].ToString());
var tenantAdminUri = new Uri(rootSiteUrl);
string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, realm).AccessToken;
using (var adminContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
{
// Set the time out as high as possible
adminContext.RequestTimeout = int.MaxValue;
var tenant = new Tenant(adminContext);
var properties = new SiteCreationProperties()
{
Url = webUrl,
Owner = listItem["AdminAccount"].ToString(),
Title = listItem["Title"].ToString(),
Template = listItem["Template"].ToString(),
};
//start the SPO operation to create the site
SpoOperation op = tenant.CreateSite(properties);
adminContext.Load(op, i => i.IsComplete);
adminContext.RequestTimeout = int.MaxValue;
adminContext.ExecuteQuery();
}
// Do some branding for the new site
SetThemeToNewSite(webUrl);
return webUrl;
}
示例15: CreateSiteCollection
public string CreateSiteCollection()
{
var user = GetSpUser.ResolveUserById(_ctx, _actionRequest.User);
var tenant = new Tenant(_ctx);
var webUrl =
$"https://{_actionRequest.TenantName}.sharepoint.com/{_siteCollectionRequest.ManagedPath}/{_actionRequest.Name}";
if (tenant.SiteExists(webUrl))
{
// "Site already existed. Used URL - {0}"
}
else
{
var newsite = new SiteCreationProperties
{
Title = _actionRequest.Name,
Url = webUrl,
Owner = user.Email,
Template = "STS#0",
Lcid = _siteCollectionRequest.Lcid,
TimeZoneId = _siteCollectionRequest.TimeZoneId,
StorageMaximumLevel = _siteCollectionRequest.StorageMaximumLevel,
StorageWarningLevel = _siteCollectionRequest.StorageMaximumLevel,
UserCodeMaximumLevel = 0,
UserCodeWarningLevel = 0
};
SpoOperation op = tenant.CreateSite(newsite);
_ctx.Load(tenant);
_ctx.Load(op, i => i.IsComplete);
_ctx.ExecuteQuery();
var step = 0;
while (!op.IsComplete)
{
step = step + 1;
Updatehelper.UpdateProgressView($"{step} Creating site collection", _actionRequest);
Thread.Sleep(10000);
op.RefreshLoad();
_ctx.ExecuteQuery();
}
}
var site = tenant.GetSiteByUrl(webUrl);
var web = site.RootWeb;
web.Description = _actionRequest.Description;
web.Update();
_ctx.Load(web);
_ctx.ExecuteQuery();
return web.Url;
}