gpt4 book ai didi

Sharepoint 2010 - 使用自定义站点模板从代码创建站点

转载 作者:行者123 更新时间:2023-12-01 01:33:43 31 4
gpt4 key购买 nike

我正在从 Silverlight Webpart 创建一个新的共享点站点。我正在使用 ClientContext 模型,它非常适合团队网站模板 (STS#0)。我需要从我创建的自定义站点模板创建一个新站点,但我不知道如何引用此模板来指定一个 Web 模板,它是按名称指定的,并且只能引用标准模板之一。

这是我的代码:

  string siteUrl = App.RootSite;
string siteDescription = project.projectName; // "A new project site.";
int projectLanguage = 1033;
string projectTitle = project.projectName; // "Project Web Site";
string projectUrl = project.projectURL; //"projectwebsite";
bool projectPermissions = false;
string webTemplate = "STS#0"; //TODO: reference custom site template

try
{
ClientContext clientContext = new ClientContext(siteUrl);
Web oWebsite = clientContext.Web;

WebCreationInformation webCreateInfo = new WebCreationInformation();
webCreateInfo.Description = siteDescription;
webCreateInfo.Language = projectLanguage;
webCreateInfo.Title = projectTitle;
webCreateInfo.Url = projectUrl;
webCreateInfo.UseSamePermissionsAsParentSite = projectPermissions;
webCreateInfo.WebTemplate = webTemplate;

oNewWebsite = oWebsite.Webs.Add(webCreateInfo);

clientContext.Load(
oNewWebsite,
website => website.ServerRelativeUrl,
website => website.Created,
website => website.Id);

clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFail);

}
catch (Exception e)
{
MessageBox.Show(e.Message);
}

最佳答案

遍历所有可用模板,您会发现自定义模板名称前面有 guid:{A13D0D34-EEC2-4BB5-A563-A926F7F9681A}#ProjectSiteTemplate。

    ClientContext clientContext = new ClientContext(siteUrl);
Web oWebsite = clientContext.Web;
WebTemplateCollection templates = oWebsite.GetAvailableWebTemplates(1033, true);

clientContext.Load(templates);
clientContext.ExecuteQueryAsync(onTemplateSucceeded, null);

private void onTemplateSucceeded(object sender, ClientRequestSucceededEventArgs args)
{
UpdateUIMethod updateUI = ShowTemplates;
this.Dispatcher.BeginInvoke(updateUI);
}

private void ShowTemplates()
{
foreach (WebTemplate template in templates)
{
MessageBox.Show(template.Id + " : "
+ template.Name + " : "
+ template.Title);
}
}

关于Sharepoint 2010 - 使用自定义站点模板从代码创建站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3240967/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com