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”为团队站点模板