1

I am trying to create a site collection in Office 365 through an auto-hosted app. I am using the Microsoft.Online.SharePoint.Client.Tenant.dll and my code is as below.

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 

    }
  }

}

However, I would like to use a custom site template that I have created, instead of the "STS#0" team site template. The custom site template exists in the Solution Gallery of the site collection in which my APP is deployed. Is there a way I can upload this site template and activate it, during the creation of the new site collection programmatically?

4

1 回答 1

1

没有太多关于如何将 Microsoft.Online.SharePoint.Client.Tenant.dll 与 C# 一起使用的文档,但您可以从SharePoint 在线 Powershell 命令中了解它,因为某些 Powershell 命令基于此 DLL。

至于创建网站集,参数“Template”是你要使用的模板名称,如果要查找自定义网站模板的名称,可以使用powershell命令“ Get-SPOWebTemplate ”,它会列出所有带有名称的模板。

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

于 2014-04-21T13:38:29.790 回答