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

C# で Microsoft.Online.SharePoint.Client.Tenant.dll を使用する方法に関するドキュメントはあまりありませんが、Powershell コマンドの一部はこの DLL に基づいているため、 SharePoint オンラインの Powershell コマンドから学ぶことができます。

サイト コレクションを作成する場合、パラメーター "Template" は使用するテンプレートの名前です。カスタム サイト テンプレートの名前を見つけるには、powershell コマンド " Get-SPOWebTemplate " を使用できます。すべてのリストが表示されます。名前付きのテンプレート。

Template パラメーターと LocaleId パラメーターは、Get-SPOWebTemplate コマンドレットから返される有効な組み合わせである必要があります。

于 2014-04-21T13:38:29.790 に答える