开发者

Only get the custom templates of the site templates programmatically?

I am populating a drop down with all the templates in the site collection, however, I now would like to only get the custom templates that I have created.

My code to get the templates is:

private void getTemplates()
{
    using (SPSite siteCollection = new SPSite(server))
    {
        SPWeb parentWeb = siteCollection.OpenWeb();

        SPWebTemplateCollection Templates = siteColle开发者_StackOverflow社区ction.GetWebTemplates(1033);
        foreach (SPWebTemplate template in Templates)
        {
            ddlSiteTemplate.Items.Add(new ListItem(template.Title, template.Name));
        }
    }
}

I can for example name all custom templates so that their name starts with Custom and then have a condition in the loop to only bind the dropdown with templates that starts with this word. As topic says though I wonder if there is a way to only get the custom templates and not have to have a condition in the loop?

Thanks in advance.


You should use GetCustomWebTemplates instead, the rest of the code can remain the same, though i do not undertand what you need parentWeb for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜