3

I have created a site definition but i need to limit what sub sites can be created by the user.

How can I do this with SharePoint 2010?

thanks

1
  • We are not using the publishing feature. How can we limit the list of templates that are listed for creating sub sites?
    – dave
    Oct 27, 2010 at 17:26

2 Answers 2

4

As part of the publishing features you can add AvailableWebTemplates and AvailablePageLayouts declaratively as feature properties in onet.xml:

<Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">    <!-- Publishing -->    <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
...
<Property Key="AvailableWebTemplates" Value="*-BLANKINTERNET#1;*-BLANKINTERNET#2"/>
<Property Key="AvailablePageLayouts" Value="~SiteCollection/_catalogs/masterpage/ArticleLeft.aspx:~SiteCollection/_catalogs/masterpage/ArticleLinks.aspx:~SiteCollection/_catalogs/masterpage/ArticleRight.aspx"/>
...
</Properties>
</Feature>

The * can be replaced with a specific LCID (eg 1033) if you only want the template available for specific languages. Seperator is ; for templates and : for page layouts

2
  • Can this be done without turning on the publishing features?
    – dave
    Oct 27, 2010 at 17:23
  • SPWeb.SetAvailableWebTemplates() is what you are looking for. Filter on LCID to only allow templates for specific languages. Also remember to call update on SPweb after setting the allowed templates. msdn.microsoft.com/en-us/library/ms435526.aspx Oct 29, 2010 at 22:13
0

I would like to know if there is a declarative way to do it. But you can have a feature activtaed which receives following event whenever a new web is being created. You will have an opportunity to check for allowed templates and then redirect the users to error page if needed.

public override void WebAdding(SPWebEventProperties properties) { // Check properties.Web.WebTemplate belongs to the allowed templates... and if not do following

properties.Cancel = true; properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl; properties.RedirectUrl = "/_layouts/Custom/error.aspx"; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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