在 Office 365 上使用 JavaScript 创建网站集 (SharePoint Online)

Creating site collection with javascript on office 365 (sharepoint online)

本文关键字:网站 SharePoint Online 创建 JavaScript Office      更新时间:2023-09-26

我想使用javascript创建一个网站集,但我在网上找不到任何东西。

谢谢。

假设您使用的是 SharePoint 托管应用程序

//create sp context and get root
var clientContext = new SP.ClientContext.get_current();
var rootWeb = clientContext.site.rootWeb();
this.clientContext.load(rootWeb);
this.clientContext.executeQUery();
//set web info
var webInfo = new SP.WebCreationInformation();
webInfo.set_webTemplate('YourTemplateName');
webInfo.set_description('Your site description');
webInfo.set_title('Your site tittle');
webInfo.set_url(siteUrl);
webInfo.set_language(yourLangCode);
this.rootWeb.get_webs().add(webInfo);
this.rootWeb.update();
// save site and set callbacks
this.clientContext.load(this.rootWeb);
this.clientContext.executeQueryAsync(
    Function.createDelegate(this, this.OnSiteCreationSuccess),
    Function.createDelegate(this, this.Error));

请记住,您的模板必须与您使用的 langCode 一起保存,否则它将引发未找到的异常。