现在的位置: 首页 > 综合 > 正文

SharePoint2010的Client Object Mode 之站点操作

2012年03月12日 ⁄ 综合 ⁄ 共 1044字 ⁄ 字号 评论关闭
public static Web CreateSite(ClientContext clientCtx, string title, string url, string description)
{
try
{
WebCreationInformation webCreateInfo
= new WebCreationInformation();
webCreateInfo.Description
= description;
webCreateInfo.Language
= 1033;
webCreateInfo.Title
= title;
webCreateInfo.Url
= url;
webCreateInfo.UseSamePermissionsAsParentSite
= true;
webCreateInfo.WebTemplate
= "STS#1";

Web oNewWebsite
= clientCtx.Web.Webs.Add(webCreateInfo);

clientCtx.Load(oNewWebsite);

clientCtx.ExecuteQuery();

return oNewWebsite;
}
catch (ServerUnauthorizedAccessException suaex)
{
Console.WriteLine(suaex.Message);
}
catch (ServerException sex)
{
Console.WriteLine(sex.Message);
}

return null;
}

public static WebTemplate GetTemplate(ClientContext clientCtx, string title)
{
WebTemplateCollection templates
= clientCtx.Web.GetAvailableWebTemplates(1033, true);

IEnumerable
<WebTemplate> filteredTemplates = clientCtx.LoadQuery(templates.Where(t => t.Title == title));

clientCtx.ExecuteQuery();

if (filteredTemplates != null && filteredTemplates.Count() > 0)
return filteredTemplates.First();
else
return null;
}

注意:其中“STS#1”为空白站点模板,“STS#0”为团队站点模板

抱歉!评论已关闭.