Execute code on site creation in SharePoint 2010
-
06-12-2019 - |
Question
We're trying to create a SharePoint 2010 feature on a site collection that when active would execute code each time a web site is created. We're using Visual Studio 2010. The code will set properties on the web site (enable publishing, add some lists, set properties on the lists/libraries). We'd also settle for a console app that would do the same thing. Any ideas? Thanks.
Solution
I recommend using a Web Event Receiver to do this, and handle the 'WebProvisioned' method. This can be created as a Site collection scoped feature that will trigger for every sub website that's provisioned.
OTHER TIPS
I have just completed something similar. I create a new site collection based on user input for Title, owner, template, metadata defaults, set auditing and retention policies, etc. This is done via a workflow attached to the request list 'ItemAdded' event. I can probably break the workflow process down into digestible pieces ( it will give me incentive to write a new blog post anyway).