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)
{
base.ListAdded(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;
list.Update();
// 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"
Title="SurveyListEnforceShowOption"
Description="Should enforce the option to show the user name in the survey list"
Scope="Farm" Hidden="true"
xmlns="http://schemas.microsoft.com/sharepoint/"
ReceiverAssembly="assemblyInfo"
ReceiverClass="classInfo">
</Feature>
I do not think a feature stapling is required here however feel free to suggest on this..
Update
As suggested, the above feature can't be used.
Please let me know if the below can be used.
Feature.xml
<Feature
Scope="Site"
Title="Survey list update"
Id="C8F0E2DA-846D-43c0-84B1-56463178E91A"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Elements.xml"/>
</ElementManifests>
</Feature>
Element.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers
**ListTemplateId="102">**
<Receiver>
<Name>SurveryShowUser</Name>
<Type>ListAdding</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>AssemblyInfo</Assembly>
<Class>ClassInfo</Class>
</Receiver>
</Receivers>
</Elements>
Feature Stapping
Feature.xml
<Feature Id="4AF9999A-0517-4224-9ED3-D2F9F87D92E2"
Title="demo.Survey.FeatureStapling"
Description="Description."
Version="1.0.0.0"
Scope="WebApplication"
Hidden="FALSE"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="stapling.xml" />
</ElementManifests>
</Feature>
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" />
</Elements>
Installation:
- Install-SPFeature -path "surveyShowUser"
- Install-SPFeature -path "surveyShowUserStappling"
- Enable-SPFeature -identity "surveyShowUserStappling" -URL http://
Is it ok? or am I missing something here?
kindly help..