目录
article
VisualStudio开发WebPart之创建网站
VisualStudio开发WebPart之创建网站
在开发webpart的过程中,会出现新建网站的功能。此时需要用到SPWebCollection类中的Add方法。
该方法有以下三种重载方式:
重载方式1
public SPWeb Add(string strWebUrl);
参数:
strWebUrl(包含新网站url的string字符串)
重载方式2
public SPWeb Add(string strWebUrl, string strTitle, string strDescription, uint nLCID, SPWebTemplate WebTemplate, bool useUniquePermissions, bool bConvertIfThere);
参数:
strWebUrl(包含新网站url的string字符串)strTitle(包含新网站标题的string字符串)strDescription(包含新网站描述的string字符串)nLCID(一个不带符号的32位的integer类型的数字来指定locale ID)WebTemplate(一个Microsoft.SharePoint.SPWebTemplate类型的对象,用来表示网站定义或者网站模板)useUniquePermissions(true表示不从其他网站继承权限;false表示从其他网站继承权限)bConvertIfThere(true表示如果存在和新网站同名的文件夹,则奖其转换为新网站;false表示无论存在与否,不转换)
重载方式3
public SPWeb Add(string strWebUrl, string strTitle, string strDescription, uint nLCID, string strWebTemplate, bool useUniquePermissions, bool bConvertIfThere);
参数:
strWebUrl(包含新网站url的string字符串)strTitle(包含新网站标题的string字符串)strDescription(包含新网站描述的string字符串)nLCID(一个不带符号的32位的integer类型的数字来指定locale ID)strWebTemplate(一个string字符串,用来表示网站定义或者网站模板)useUniquePermissions(true表示不从其他网站继承权限;false表示从其他网站继承权限)bConvertIfThere(true表示如果存在和新网站同名的文件夹,则奖其转换为新网站;false表示无论存在与否,不转换)
下面是使用这个方法的一个例子:
/// <summary>
/// サイト作成
/// </summary>
/// <param name="webUrl">URL</param>
/// <param name="title">タイトル</param>
/// <param name="description">記述</param>
/// <param name="locationId">LocationId</param>
/// <param name="webTemplate">テンプレート</param>
/// <param name="useUniquePermissions">権限</param>
/// <param name="bConvertIfThere">存在場合、エラー</param>
/// <param name="spWeb">SPWeb</param>
/// <returns>Trueの場合、サイト作成成功、Falseの場合、サイト作成失敗</returns>
private bool CreateSite(string webUrl, string title, string description,
uint locationId, SPWebTemplate webTemplate,
bool useUniquePermissions, bool bConvertIfThere,
SPWeb spWeb)
{
bool siteSuccess = true;
try
{
spWeb.Webs.Add(webUrl, title, description, (uint)locationId, webTemplate, useUniquePermissions, bConvertIfThere);
}
catch (Microsoft.SharePoint.SPException ex)
{
//サイト作成操作中異常発生する場合、logでError出力
log4net.ILog log = log4net.LogManager.GetLogger(this.GetType());
log4net.MDC.Set("messageID", "COE00005");
log.Error(GetMessageInfo("COE00005"), ex);
siteSuccess = false;
}
return siteSuccess;
}