Sharepoint 从应用程序在Office 365中创建新网站集

Sharepoint 从应用程序在Office 365中创建新网站集,sharepoint,office365,office365-apps,Sharepoint,Office365,Office365 Apps,我需要从Office 365中的应用程序中以编程方式创建新网站集。我所说的新网站集是指创建后,它应该出现在Office 365的“管理-->Sharepoint”选项卡下的网站集列表中。我尝试在我创建的sharepoint托管应用程序中使用下面类似的代码 //create sp context and get root var clientContext = new SP.ClientContext.get_current(); var rootWeb = clientContext.site.

我需要从Office 365中的应用程序中以编程方式创建新网站集。我所说的新网站集是指创建后,它应该出现在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));
但是,这只是在网站集下创建了一个子网站来承载我的应用程序


如果您对我如何实现此功能有任何建议,我们将不胜感激。

可以使用SharePoint对象模型2013完成此操作,您需要的函数位于程序集中:Microsoft.Online.SharePoint.Client.Tenant.dll,安装SharePoint客户端对象模型2013后,位于C:\Program Files\SharePoint客户端组件\程序集

这方面没有太多文档,但是有创建网站集的命令,所以我认为可以用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 

        }
    }

}

可以使用SharePoint对象模型2013执行此操作,您需要的功能位于程序集:Microsoft.Online.SharePoint.Client.Tenant.dll中,安装SharePoint客户端对象模型2013后,该程序集位于C:\Program Files\SharePoint Client Components\assembly

这方面没有太多文档,但是有创建网站集的命令,所以我认为可以用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 

        }
    }

}

谢谢你,马特。这正是我想要的。难以置信的是,要获得关于它的文档有多么困难。您知道是否可以通过编程方式将用户或组的权限分配给创建的新网站集吗?我认为这是可能的,因为它已在powershell命令中:。此类应为donw:。但是我没有这样的例子。非常感谢马特。这正是我想要的。难以置信的是,要获得关于它的文档有多么困难。您知道是否可以通过编程方式将用户或组的权限分配给创建的新网站集吗?我认为这是可能的,因为它已在powershell命令中:。此类应为donw:。但我没有这样的例子。