随着应用程序的推出和解决方案的消失。以编程方式创建网站集的最佳方式是什么?我是内部部署的。 可以用JavaScript来完成吗?我可以使用js创建子站点,但Site Collections又如何?SharePoint 2013 - 以编程方式创建网站集
我发现了一些c#代码来创建一个网站集,但我从哪里运行它?在应用程序中?
随着应用程序的推出和解决方案的消失。以编程方式创建网站集的最佳方式是什么?我是内部部署的。 可以用JavaScript来完成吗?我可以使用js创建子站点,但Site Collections又如何?SharePoint 2013 - 以编程方式创建网站集
我发现了一些c#代码来创建一个网站集,但我从哪里运行它?在应用程序中?
我已经使用事件接收器(c#)以编程方式成功创建了网站集。微软已经证实,用JavaScript创建网站集是不可能的。我以为我会分享我的整体解决方案,因为我从头到尾没有看到完整的文档。
添加事件接收器
下面是eventreceiver.cs文件的代码:
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
namespace SharePointProject5.EventReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item is being added.
/// </summary>
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
//create admin service reference
SPAdminService.Admin admService = new SPAdminService.Admin();
//grant proper admin credentials to admin service
admService.Credentials = new System.Net.NetworkCredential("Farmaccount", "Password", "Domain");
try
{
//specify new site collection path
String SitePath = "http://twv101sp13/pm/new2013";
//setup properties to create the site, see reference below for more info
admService.CreateSite(SitePath, "new site", "description", 1033, "STS#1", "bluebunny\\sp13admin", "System Account", "[email protected]", "", "");
}
catch (System.Web.Services.Protocols.SoapException ex)
{
//I added this section so any errors would be logged in the server application log
SPSecurity.RunWithElevatedPrivileges(
delegate()
{
System.Diagnostics.EventLog.WriteEntry("Application", "Message:\n" + ex.MRessage + "\nDetail:\n" +
ex.Detail.InnerText +
"\nStackTrace:\n" + ex.StackTrace);
});
}
}
}
}
所以,你只希望这在一定名单增加了运行一个项目,所以你必须修改Elements.xml文件。
打开的Elements.xml,与<Receivers ListUrl="http://{SharepointSite}/{targetListName}">
替换该行<Receivers ListTemplateId="101">
- 这是这样,我们也可以仅锁定列表,而不是在该网站的所有列表
右键单击您的项目和部署
您应该可以创建一个新项目,然后检查您的新网站集。
我遇到的一个问题是网站无法以数字字符开头。
在这篇文章的底部,它讲述了如何调试功能事件接收器。如果没有,我会在水中已经死了:http://msdn.microsoft.com/en-us/library/ee231550.aspx
这三篇文章帮助了很多:
我不知道如何在Javascript中执行此操作,但在任何可以使用提升特权运行C#代码的地方,只需调用SPSite.CreateSelfServiceSite的任何重载即可。 – Renan