开发者

Only get the custom templates of the site templates programmatically?

开发者 https://www.devze.com 2023-02-04 10:53 出处:网络
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.

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

精彩评论

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