In our SharePoint 2010 environment, we want to enforce the users to choose the option "show user names in the survey list" (survey list) however there may be a time when user may choose "No" to this option instead of "Yes".

so we decided to utilize the ListAdded event receiver.

the below code is in my mind.

public class DoNotCreateSurvey : SPListEventReceiver
   public override void ListAdded(SPListEventProperties properties)

       SPList list = properties.List;

       // revert the list settings whenever a end-users chooses anonymous surveys
       if (list != null && !list.ShowUser && list.BaseType.ToString().Equals("Survey", StringComparison.CurrentCultureIgnoreCase)){
           this.EventFiringEnabled = false;
           list.ShowUser = true;

           // put notification code here
           this.EventFiringEnabled = true;

I know, it can be deployed against a subsite however the same feature should be available/associated with all the web-applications(all the site-collections & all the sub-sites which are all already exists and the future once) are in the farm.

let me know if it can be used like this:

    <Feature Id="C8F0E2DA-846D-43c0-84B1-56463178E91A"  
      Description="Should enforce the option to show the user name in the survey list"
      Scope="Farm"  Hidden="true"  

I do not think a feature stapling is required here however feel free to suggest on this..


As suggested, the above feature can't be used.

Please let me know if the below can be used.


      Title="Survey list update" 
        <ElementManifest Location="Elements.xml"/>


    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">

Feature Stapping


    <Feature Id="4AF9999A-0517-4224-9ED3-D2F9F87D92E2"
        <ElementManifest Location="stapling.xml" />


    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <FeatureSiteTemplateAssociation Id="C8F0E2DA-846D-43c0-84B1-56463178E91A" TemplateName="STS#0" />
        <FeatureSiteTemplateAssociation Id="C8F0E2DA-846D-43c0-84B1-56463178E91A" TemplateName="STS#1" />
        <FeatureSiteTemplateAssociation Id="C8F0E2DA-846D-43c0-84B1-56463178E91A" TemplateName="STS#2" />
        <FeatureSiteTemplateAssociation Id="C8F0E2DA-846D-43c0-84B1-56463178E91A" TemplateName="........." />
        <FeatureSiteTemplateAssociation Id="C8F0E2DA-846D-43c0-84B1-56463178E91A" TemplateName="........" />
        <FeatureSiteTemplateAssociation Id="C8F0E2DA-846D-43c0-84B1-56463178E91A" TemplateName="MYSITEPER" />


  1. Install-SPFeature -path "surveyShowUser"
  2. Install-SPFeature -path "surveyShowUserStappling"
  3. Enable-SPFeature -identity "surveyShowUserStappling" -URL http://

Is it ok? or am I missing something here?

kindly help..

2 Answers 2


By design ListAdded can be hosted by SPWeb or SPSite only as documented here. So Feature Stapling cannot be avoided if you want to enforce that across the farm.

UPDATE: As per MSDN Documentation, If the Receivers tag has no ListTemplateId or ListUrl attribute, the event receiver is registered at the same scope as the Feature. Which means you should not use ListTemplateId and ListUrl.

On Feature Stapling, as another answer suggests, you should use GLOBAL template to attach to all installed Site Templates.

Another thought: I am not sure you are covered by just capturing the ListAddedEvent. Those having enough access can also change this setting later on.

  • can you please suggest me on feature stapling stuff.. Oct 6, 2011 at 19:28
  • Yes, this option is also blocked in the list general settings. Oct 13, 2011 at 5:56

To elaborate some more about the stapling solution.

As Microsof says for SharePoint 2007 (but the same is valid for the 2010 version) "Feature stapling is a concept that allows you to attach (or staple) a SharePoint Feature to a SharePoint site definition without modifying the original site definition files in any way". In that sense, stapling is a valid solution when you need to apply some new logic to an existing template (OOTB or a custom template - editing templates that are in use is not supported and can lead to problems).

In your case you could try to staple your custom feature to all the available site templates so that anytime a new site will be created your feature will be activated by default. This page on MSDN provides more info about the topic. You should use something like:

Id = "your custom feature guid" 
TemplateName = "GLOBAL"> 

Basically you must define a stapler feature that will attach your secondary "staplee" feature to a specific site definition (or multiple site definitions if you need to, see the following comments for more details). In the stapler feature you will define the id of the feature to staple and the name of the template the feature should be stapled to. As a result, any new site created using the template will automatically end with your feature active.

NOTE: you should use the template name GLOBAL to staple your feature to all the available templates. Some documentation sources uses the name "GLOBAL#0" but from what I saw it won't work that way.

Also notice that this solution won't work for any already-created site (someone please tell me if I am wrong on this point).

(Edited to add some more explanation about Feature Stapling)

  • 1
    if you staple to global, remember that Blank site is not included, hence you must staple to STS#1 also Oct 10, 2011 at 14:18
  • I knew that I had forgot something. Ander is right, any template that sets the AllowGlobalFeatureAssociations property to false will be excluded from a GLOBAL stapling. The blank site template is one example of such templates - be carefull if your environment includes third-party templates that could use that property (better be safe than sorry).
    – SPArcheon
    Oct 10, 2011 at 14:29

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.