【问题标题】:Sharepoint 2010 - Create Site from Code using Custom Site TemplateSharepoint 2010 - 使用自定义站点模板从代码创建站点
【发布时间】:2010-07-13 19:59:01
【问题描述】:

我正在从 silverlight webpart 创建一个新的共享点站点。我正在使用 ClientContext 模型,它非常适合团队网站模板 (STS#0)。我需要从我创建的 CUSTOM 网站模板创建一个新网站,但我不知道如何引用此模板,因为它是按名称指定的 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);
  }

【问题讨论】:

    标签: sharepoint sharepoint-2010


    【解决方案1】:

    遍历所有可用模板,您会发现自定义模板名称前面有 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);
        }
    }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 链接用于服务器对象模型;海报正在使用客户端对象模型
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-10
      • 2011-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      相关资源
      最近更新 更多