I need the steps on how to attach event receiver whenever any new site is created. I have not tried this before. I need the detailed step on creating event receiver on site creation
1 Answer
If it's creation of a subsite (SPWeb) you want to catch then you can use SPWebEventReceiver.WebProvisioned
But if it's a new SiteCollection then you need to stable a feature to the WebTemplate and then react to the SPFeatureReceiver.FeatureActivated
-
I need to fire the event when any new site is created under this RootSite/site/site/NewSite. Whenever the NewSite is created event sholud be fired. For this do i need to use WebProvisioned or WebAdding method– DRSCommented May 19, 2015 at 4:45
-
@Ishani WebAdding happens before the site is created (at all) primary giving you the posibility of preventing the addition. WebProvisioned happens when everything has been created. Commented May 19, 2015 at 6:42
-
Thanks.. So do i need to activate any extra feature for WebProvisioned method. I am referring to this link [blog.qumsieh.ca/2010/10/07/… and when i tried to debug after the subsite is created, the breakppoint doesn't get activated in WebProvisioned method– DRSCommented May 19, 2015 at 6:59
-
No the only feature to that needs activation is the one with your Event Receiver make sure it's at Site Collection scope (Site in Feature.xml). And it should fire on any subsite created after that. Commented May 19, 2015 at 8:40
-
Can you explain why we need to put the scope as site collection– DRSCommented May 19, 2015 at 9:49