Wednesday 16 December 2015

Why we won't get SPContext in Features

You can't get SPContext inside handlers - this is by design. You should use event properties passed as argument to the handler to get reference to current web, list item etc.

Timer Jobs, Feature Receivers, Service Application Solutions are not invoked synchronously by user action, so they are not associated with HTTPRequest and thus they do not have access to SPContext.
You have to get it :


SPSite site = properties.Feature.Parent as SPSite;

No comments:

Post a Comment