sharepoint 2013-在Office 365 APP中使用自定义网站模板以编程方式创建网站集



我正试图通过一个自动托管的应用程序在Office 365中创建一个网站集。我正在使用Microsoft.Online.SharePoint.Client.Tenant.dll,我的代码如下。

using System;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using System.Security;
namespace SharePoint123
{
 class Program
 {
    static void Main(string[] args)
    {
        //please change the value of user name, password, and admin portal URL
        string username = "xxxx@xxxx.onmicrosoft.com";
        String pwd = "xxxx";
        ClientContext context = new ClientContext("https://xxxx-admin.sharepoint.com");
        SecureString password = new SecureString();
        foreach (char c in pwd.ToCharArray())
        {
            password.AppendChar(c);
        }
        context.Credentials = new SharePointOnlineCredentials(username, password);
        Tenant t = new Tenant(context);
        context.ExecuteQuery();//login into SharePoint online

        //code to create a new site collection
        var newsite = new SiteCreationProperties()
        {
            Url = "https://xxxxx.sharepoint.com/sites/createdbyProgram1",
            Owner = "xxxxx@xxxxx.onmicrosoft.com",
            Template = "STS#0", //using the team site template, check the MSDN if you want to use other template
            StorageMaximumLevel = 100,
            UserCodeMaximumLevel = 100,
            UserCodeWarningLevel = 100,
            StorageWarningLevel = 300,
            Title = "CreatedbyPrgram",
            CompatibilityLevel = 15, //15 means Shapoint online 2013, 14 means Sharepoint online 2010
        };
        t.CreateSite(newsite);
        context.ExecuteQuery();
        //end 
    }
  }
}

但是,我想使用我创建的自定义站点模板,而不是"STS#0"团队站点模板。自定义网站模板存在于部署我的应用程序的网站集的解决方案库中。在创建新网站集的过程中,有没有一种方法可以上传此网站模板并以编程方式激活它?

关于如何将Microsoft.Online.SharePoint.Client.Tenant.dll与C#一起使用的文档不多,但您可以从SharePoint联机Powershell命令中学习,因为某些Powershell命令基于此dll。

对于创建网站集,参数"Template"是您要使用的模板的名称,对于查找自定义网站模板的名称时,您可以使用powershell命令"GetSPOWebTemplate",它会列出所有具有名称的模板。

注意,Template和LocaleId参数必须是Get-SPOWebTemplate cmdlet返回的有效组合。

最新更新