1

我需要以编程方式从 Office 365 中的应用程序中创建新网站集。我所说的新网站集的意思是,在创建后,它应该出现在 Office 365 的“管理员”->“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));

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

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

4

1 回答 1

4

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

这方面的文档不多,但SharePoint Online 命令行管理程序有创建网站集的命令,所以我认为可以用 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 

        }
    }

}
于 2014-01-22T14:06:27.943 回答