Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is it possible to turn on a custom feature atomically when you create a new site collection? I have a branding feature that I want to be turned on by default for each site collection made.

share|improve this question

3 Answers 3

up vote 9 down vote accepted

For now, SharePoint 2010 does not support event for site collection adding or added.So it is not possible to do it programmatically

Yes, You can plugin your feature to the site definition used for the site collection by "Feature Stapling".

You can define a feature at scope of Web application. It will automatically activate the stapled feature(which is your feature) within every site (in web application) that is based on the site definition you provide in <FeatureSiteTemplateAssociation> like below sample.

If you want to activate the feature for all kind of sites in web application, you can associate stapling a feature to global site definition(TemplateName=" GLOBAL") and blank site (TemplateName=" STS#1").

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureSiteTemplateAssociation   
Id="edcdcd75-dff2-479d-ac32-b37f8fa9d459"
TemplateName=" GLOBAL" />
<FeatureSiteTemplateAssociation   
Id="edcdcd75-dff2-479d-ac32-b37f8fa9d459"
TemplateName=" STS#1" />
</Elements>

Change the Id to your feature Id in above sample.

The scope of the feature that does the stapling must be higher than the features being stapled. For example, a feature at the site collection scope can staple only features at site-level scope. So, you can fine tune the your feature scope accordingly

share|improve this answer
    
As our moderator Anders remembered me in another post, be carefull that some site definitions may use the "AllowGlobalFeatureAssociations" in which case they will be excluded from GLOBAL stapling. If you are using any of such definition (for example the Blank Site - STS#1) be sure to include them explicitly. –  SPArchaeologist Oct 19 '11 at 7:03
    
Yes, It is off for STS#1 that's why I included explicitly in the above example –  Amit Kumawat Oct 19 '11 at 10:02
    
Right, I added that comment only for readability sake (other custom templates could use the "AllowGlobalFeatureAssociations" so it always better to doublecheck that option if some issues emerges). I had already assumed that you knew that from you post. –  SPArchaeologist Oct 19 '11 at 10:14

You can create a a Feature of Web Application Scope and deploy it on your Web Application. So whenever you will create a site collection in your web app, that feature will be activated on it.

You can also set the Automatic Activate property of the Feature to TRUE.

share|improve this answer
    
Sadly the scope of the feature Iwant turned on can only be site and lower as I need to put files in the MasterPageGallery –  John Oct 18 '11 at 11:04
    
John, the feature would live at the Web Application level, but applied to anything under it (ie: site or web). The feature would have to be one layer above what you wanted to detect creation of. –  webdes03 Oct 18 '11 at 13:27

Yes, it's possible. The (probably) easiest way is to use feature stapling. Then you can say that all new instances of e.g. STS#0 (Team site), should activate this feature.

<FeatureSiteTemplateAssociation Id="b8f334a0-1ffe-420d-b6e2-54a9faa6ba95" TemplateName="STS#0" />
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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