0

We want to remove all site templates except custom templates under Create > 'Sites and Workspaces'. and we only want to allow custom templates... Custom template can grow over the time by saving site as template.

When I activate below feature code it removes all other templates as required and only shows custom templates but if I save site as template which creates new custom template... new custom template doesn't appear under Create > 'Sites and Workspaces'.

How can my feature look for newly created templates?

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWeb web = properties.Feature.Parent as SPWeb;    // Get the SPWeb object for current site
        uint lang = web.Language;
        web.AllowAllWebTemplates(); // Resets the available Web templates on the Web site to the complete set of Web templates.

        SPWebTemplateCollection existingWebTemps = web.GetAvailableWebTemplates(lang);
        Collection<SPWebTemplate> newWebTemps = new Collection<SPWebTemplate>();

        for (int i = 0; i < existingWebTemps.Count; i++)
        {
            if (existingWebTemps[i].IsCustomTemplate)
            {
                newWebTemps.Add(existingWebTemps[i]);
            }
        }

        web.SetAvailableWebTemplates(newWebTemps, lang);
        web.Update();
    }
0

I made a similar feature not long ago and I was able to achieve this by looking at all existing templates and matching the names against the know out of the box templates. If the current template is one of those then hide it. It's very cumbersome but it works.

You need to list each template by name so a bit tedious...

Just to add, I do have the code somewhere so I can dig it out and post it here when I get a chance.

I see that you are taking the reverse approach of hiding not required templates instead of showing templates which are required and making them available.

I had thought about that option but because of nature of the solution I was trying to come up with some simpler solution but thanks for the reply if nothing else I'll have to go that route. :)

I was wondering can we not program something where we show items based on DisplayCategory i.e. Collaboration, Meetings, Publishing, Custom etc.? It's not working for me.

  • I see that you are taking the reverse approach of hiding not required templates instead of showing templates which are required and making them available. I had thought about that option but because of nature of the solution I was trying to come up with some simpler solution but thanks for the reply if nothing else I'll have to go that route. :) I was wondering can we not program something where we show items based on DisplayCategory i.e. Collaboration, Meetings, Publishing, Custom etc.? It's not working for me. – Connect The Dots Feb 13 '14 at 20:31
  • Hi again, to be honest for that I worked on that wouldn't have met our requirements as we wanted certain templates hidden only so we had to name each one. I was able to make the job a bit easier by checking if the name contained a word such as 'database' to hide a group of templates rather than making each database site template. Good luck. – user23429 Feb 13 '14 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.