I have a feature for deploying masterpages that I am trying to activate upon install(deploy). The following snippets of code are in the EventReceiver.cs. I am getting a null when attempting to reference properties.Feature (the error actually occurs when calling .Parent since properties.Feature is null. How do I reference the current site in the FeatureInstalled to Activate it? SPContext.Current also returns null in Feature installed.
public static class Extensions
{
public static SPWeb GetWeb(this SPFeatureReceiverProperties properties)
{
SPWeb site;
if (properties.Feature.Parent is SPWeb)
{
site = (SPWeb)properties.Feature.Parent;
}
else if (properties.Feature.Parent is SPSite)
{
site = ((SPSite)properties.Feature.Parent).RootWeb;
}
else
{
throw new Exception("SPWeb not available - Feature is not Site or Web Scoped.");
}
return site;
}
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
SPWeb curweb = properties.GetWeb();
curweb.Features.Add(new Guid("{GUID_HERE}"));
}