通过APP在Office 365中创建新的网站集 [英] Creating new site collection in Office 365 from an APP

查看:106
本文介绍了通过APP在Office 365中创建新的网站集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Office 365中的应用程序内以编程方式创建新的网站集.我所说的新网站集是指创建后,它应该出现在Office 365的管理->共享点"选项卡下的网站集列表中.我尝试在共享点托管的应用程序中使用以下类似代码创建,

I have a requirement to create a new site collection from within an App in Office 365 programmatically. What I mean by a new site collection, is that after creation, it should appear on the list of site collections under the Admin --> Sharepoint tab of Office 365. I tried using a similar code below within a sharepoint hosted app that i had created,

//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));

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

However this just creates a sub site under the site collection that hosts my App.

任何有关如何实现此目标的建议将不胜感激.

Any suggestions on how i could implement this would be greatly appreciated.

推荐答案

可以使用SharePoint Object Model 2013完成,所需的功能在程序集中:Microsoft.Online.SharePoint.Client.Tenant.dll,即安装SharePoint客户端对象模型2013后,位于C:\ Program Files \ SharePoint客户端组件\程序集.

It can be done with SharePoint Object Model 2013, the functions you need are inside the assembly: Microsoft.Online.SharePoint.Client.Tenant.dll, which is located at C:\Program Files\SharePoint Client Components\Assemblies after you install the SharePoint Client Object model 2013.

关于这方面的文档并不多,但是

There's not much doc on this, but SharePoint Online Management Shell has the command to create the site collection, so I think it can be done with C# and figured it out. The code snippet shows how to do it.

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 

        }
    }

}

这篇关于通过APP在Office 365中创建新的网站集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆