Monday, 15 July 2013

Feature Receivers in SharePoint

When used it:The Feature Receivers can be used If you want to perform any action programmatically using C# code like when feature is installed, uninstalled, activated or deactivated.
e.g. I will share one of my best experience about on feature receivers when it’s most required.
Task: I want to develop one custom master page and set that master page as default master page to the site.
Sol: Below are my development approaches on it.
  1. First created a custom master page using existing master page through SharePoint designer.
  2. Deployed that custom master page to the master page gallery using “Feature”.
  3. Finally, write c# code to set our masterpage as default master to the site using “feature receiver”[means I wrote c# code to set our custom master page as default master page inside of “FeatureActivated” event]. Here the feature receiver will run whenever the feature is activated.
Feature’s Scope levels:SharePoint Features can be targeted at the Farm, Web Application, Site Collection or Web Site scope. The target will effect things like where you can manage the feature activation from in the UI and at which point (and how many times) the Feature receiver events are called.

Scope
Activate/Deactivate Features (2007)
Web Site
Site Actions > Site Settings > Site Administration > Site features
Site Collection
Site Actions > Site Settings > Site Collection Administration > Site collection features
Web Application
SharePoint Central Admin > Application Management > SharePoint Web Application Management > Manage Web application features
Farm
SharePoint Central Admin > Operations > Global Configuration > Manage farm features

Some remember points on Feature Receivers:
  • As a general rule, if you override the FeatureActivated handler, you should also override theFeatureDeactivating handler to reverse what your code did in the FeatureActivated handler. Similarly, if you override the FeatureInstalled handler, you should also override theFeatureUninstalling handler to reverse what your code did in the FeatureInstalled handler.
  • It is not possible to cancel an installation or uninstallation through Feature events.
  • We can deploy feature receivers through sandbox solution.

How to debug Feature Receiver:

Best method to write feature receiver:

My Best References:

No comments:

Post a Comment