【问题标题】:Creating a new site sharepoint 2010 under parent site with my custom template Programatically using visual studio 2010使用我的自定义模板在父站点下创建一个新站点 sharepoint 2010 以编程方式使用 Visual Studio 2010
【发布时间】:2010-09-19 01:36:13
【问题描述】:

我有一个父网站,我想在其下使用 Visual Studio 2010 动态创建子网站。

我要创建的子网站有一个共同的结构(在列表和自定义方面)。

所以我将模板保存在sharepoint 2010中,它变成了wsp并进入了解决方案库。

现在我如何使用这个模板,比如 mytemplate.wsp,在 Visual Studio 中创建站点。

我试过了

使用(SPSite 站点 = 新 SPSite ("http://infml01132:5566/sites/VRND" ))

        {

            using (SPWeb web = site.OpenWeb())

            {



                SPWebTemplateCollection myTemplates = site.GetCustomWebTemplates(Convert .ToUInt32(web.Locale.LCID));

                //SPWebTemplateCollection temlates1 = site.GetCustomWebTemplates(1033);

                //SPWebTemplateCollection temlates = site.GetWebTemplates(1033);

                //SPCustomWebTemplate

                SPWebTemplate subsitetemplate = myTemplates["vrndtmpl" ];



                web.Webs.Add("subsite1" , "rnd subsite1" , "subsite description changed" , Convert .ToUInt16(1033), subsitetemplate, false , false );

            }

        }

但我没有在 mytemplates 集合中找到我的模板。

谢谢

【问题讨论】:

    标签: visual-studio-2010 sharepoint-2010


    【解决方案1】:

    我们正在使用此代码按名称检索站点模板:

    private SPWebTemplate GetSiteTemplate(SPSite site, string templateName, int lcid)
    {
        foreach (SPWebTemplate webTemplate in site.GetWebTemplates(lcid))
        {
            if (webTemplate.Name.ToLower().Contains(templateName.ToLower()))
            {
                return webTemplate;
            }
        }
        return null;
    }
    

    这是 100% 的作品。 所以,在你的情况下,你应该写:

    using (SPSite site = new SPSite ("http://infml01132:5566/sites/VRND"))
    {
        using (SPWeb web = site.OpenWeb())
        {
            SPWebTemplate subsitetemplate = GetSiteTemplate(site, "vrndtmpl", 1033);
            web.Webs.Add("subsite1" , "rnd subsite1" , "subsite description changed" , uint(1033), subsitetemplate, false , false);
         }
    }
    

    另外,请确保您已将站点模板部署在 SiteTemplates 目录下,并将相应的 webtemp.xml 文件部署到 \TEMPLATE\1033\XML 或通过功能部署它,如here 所述。

    【讨论】:

    • 嘿,非常感谢 omlin。你的方法帮助了我,我使用了 getavailablewebtemplates 方法。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多