随着应用程序的推出,以及解决方案的消失。以编程方式创建网站集的最佳方法是什么?我是内部部门。 是否可以使用JavaScript完成?我可以使用js创建子网站,但网站集可以创建什么?
我找到了一些用于创建网站集的c#代码,但是我从哪里运行它?在App?
答案 0 :(得分:2)
我已使用事件接收器(c#)以编程方式成功创建了网站集。 Microsoft已确认无法使用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", "cslee@bluebunny.com", "", "");
}
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 ListTemplateId="101">
替换为<Receivers ListUrl="http://{SharepointSite}/{targetListName}">
- 这样我们就可以只定位该列表而不是网站上的所有列表
右键单击您的项目并部署
您应该可以创建新项目,然后检查新的网站集。
我遇到的一个问题是网站无法以数字字符开头。
在本文的底部,它讲述了如何调试功能事件接收器。没有它,我就会死在水中:http://msdn.microsoft.com/en-us/library/ee231550.aspx
这三篇文章有很多帮助: