从APP在Office 365中创建新网站集

时间:2014-01-21 20:38:42

标签: sharepoint office365 office365-apps

我需要以编程方式从Office 365中的应用程序中创建新的网站集。我对新网站集的意思是,在创建之后,它应该出现在Admin - >下的网站集列表中。 Office 365的Sharepoint选项卡。我尝试在我创建的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));

但是,这只会在托管我的应用程序的网站集下创建一个子网站。

对于如何实现这一点的任何建议将不胜感激。

1 个答案:

答案 0 :(得分:4)

可以使用SharePoint Object Model 2013完成,您需要的功能在程序集内:Microsoft.Online.SharePoint.Client.Tenant.dll,位于C:\ Program Files \ SharePoint Client Components \ Assemblies之后您安装2013年的SharePoint客户端对象模型。

关于此问题的文档不多,但是SharePoint Online Management Shell具有创建网站集的命令,所以我认为可以使用C#来完成它并将其弄清楚。代码段显示了如何执行此操作。

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 

        }
    }

}
相关问题