1

我正在处理需要使用客户端 api 在 SharePoint 中创建网站集的要求。我知道服务器端我们可以使用自助服务站点创建 api 来做到这一点。我也知道在 SharePoint Online 的情况下,我们有 Microsoft.Online.SharePoint.Client.Tenant.dll 可以用来创建网站集但是在我的情况下,我有一个本地环境(SharePoint 2013),我需要在其中创建一个通过客户端 api 收集网站。您能否让我知道是否有任何 API 可用于此要求。

感谢您对此提供的任何帮助。

4

3 回答 3

2

如何通过 SharePoint 2013 托管 CSOM 创建网站集

程序集中的Tenant.CreateSite 方法Microsoft.Online.SharePoint.Client.Tenant.dll用于创建网站集:

    /// <summary>
    /// Create a new site.
    /// </summary>
    /// <param name="context"></param>
    /// <param name="url">rootsite + "/" + managedPath + "/" + sitename: e.g. "https://auto.contoso.com/sites/site1"</param>
    /// <param name="title">site title: e.g. "Test Site"</param>
    /// <param name="owner">site owner: e.g. admin@contoso.com</param>
    /// <param name="template">The site template used to create this new site</param>
    /// <param name="localeId"></param>
    /// <param name="compatibilityLevel"></param>
    /// <param name="storageQuota"></param>
    /// <param name="resourceQuota"></param>
    /// <param name="timeZoneId"></param>
    internal static void CreateSite(ClientContext context, String url, String owner, String title =null, String template = null, uint? localeId = null, int? compatibilityLevel = null, long? storageQuota = null, double? resourceQuota = null, int? timeZoneId = null)
    {
        var tenant = new Tenant(context);

        if (url == null)
            throw new ArgumentException("Site Url must be specified");

        if (string.IsNullOrEmpty(owner))
            throw new ArgumentException("Site Owner must be specified");

        var siteCreationProperties = new SiteCreationProperties {Url = url, Owner = owner};
        if (!string.IsNullOrEmpty(template))
            siteCreationProperties.Template = template;
        if (!string.IsNullOrEmpty(title))
            siteCreationProperties.Title = title;
        if (localeId.HasValue)
            siteCreationProperties.Lcid = localeId.Value;
        if (compatibilityLevel.HasValue)
            siteCreationProperties.CompatibilityLevel = compatibilityLevel.Value;
        if (storageQuota.HasValue)
            siteCreationProperties.StorageMaximumLevel = storageQuota.Value;
        if (resourceQuota.HasValue)
            siteCreationProperties.UserCodeMaximumLevel = resourceQuota.Value;
        if (timeZoneId.HasValue)
            siteCreationProperties.TimeZoneId = timeZoneId.Value;
        var siteOp = tenant.CreateSite(siteCreationProperties);
        context.Load(siteOp);
        context.ExecuteQuery();

    }




//Usage
const string username = "***@***.onmicrosoft.com";
const string password = "***";
const string tenantAdminUrl = "https://***-admin.sharepoint.com/";
const string newSiteCollUrl = "https://contoso.sharepoint.com/sites/finance"
var securedPassword = new SecureString();
foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
var credentials = new SharePointOnlineCredentials(username, securedPassword);


using (var context = new ClientContext(tenantAdminUrl))
{
     context.Credentials = credentials;
     CreateSite(context, newSiteCollUrl,username);   

}
于 2014-02-10T01:30:00.603 回答
2

在本地环境中使用 CSOM 无法做到这一点。

正如您所提到的,可以在 SPO 环境中使用您列出的库 (Microsoft.Online.SharePoint.Client.Tenant.dll)。

我不确定这是否会有所帮助,但这里有可以在当前网站集中创建网站的代码:

You will also need to add using statements for System.Collections.Generic and System.Text.

// Starting with ClientContext, the constructor requires a URL to the 
// server running SharePoint. 
ClientContext context = new ClientContext("http://SiteUrl"); 

WebCreationInformation creation = new WebCreationInformation(); 
creation.Url = "web1"; 
creation.Title = "Hello web1"; 
Web newWeb = context.Web.Webs.Add(creation); 

// Retrieve the new web information. 
context.Load(newWeb, w => w.Title); 
context.ExecuteQuery(); 

label1.Text = newWeb.Title; 

此代码直接取自这里:http: //msdn.microsoft.com/en-us/library/fp179912.aspx

于 2013-08-05T17:32:20.103 回答
0

它在 2014 年 4 月的 CU 中可用

http://blogs.msdn.com/b/vesku/archive/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom.aspx

于 2014-06-26T11:19:14.400 回答