I have a feature that is manually activated. In a feature receiver I also activate the feature on any child SPWebs in existence. I would like some code to run only on the SPWeb where the feature is manually activated.
The code below won't work as I intend because the method "EnsureSourcePublicationList" will get called on all the child webs as well.
How do I call "EnsureSourcePublicationList" on only the SPWeb where the feature is activated via the UI?
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPFeature feature = (SPFeature)properties.Feature;
SPWeb web = (SPWeb)properties.Feature.Parent;
EnsureSourcePublicationList(web);
foreach (SPWeb childWeb in web.Webs)
{
try
{
childWeb.Features.Add(feature.DefinitionId, true);
}
catch (Exception ex)
{
//TODO: handle exception via logging
}
}
}