SharePoint Site Definition Provisioning Order

When you use site definitions to create sites it's often pretty unclear what the order is in which the sites are provisioned. Knowing the order can be important if you want to make several changes to your site that are dependent on each other. In that case you need to know how to make sure that the changes are executed in the right order.

Site Definition Provisioning Order

  1. Url for the site is created
  2. Global onet.xml is provisioned
  3. Site collection (SPSite) scoped features defined in onet.xml are activated in the order in which they are listed in the onet.xml
  4. Site collection scoped stapled features are activated in random order
  5. Site(SPWeb) scoped features defined in onet.xml are activated in the order in which they are listed in the onet.xml
  6. Site (SPWeb) scoped stapled features in activated in random order
  7. Listinstances defined in onet.xml are created
  8. Modules defined in onet.xml are processed (and thus this is the moment at which the default. aspx file  and other aspx files defined in the modules are added to the site)

This list tells you that if the order in which features are activated is important and you want to use feature stapling you should create dependent features.
This also tells you that the default.aspx page is the last thing that is added to the site. If you want to make changes to this file like moving around web parts on the page, or adding web parts to the page you there are a couple of ways you can go about this:

  1. You can create a feature that provisions the default.aspx page and associate another feature with that one that will contain a featurereceiver that makes changes to the default.aspx page.  – This is the recommended way to go about this
  2. You can create a web control on the master page that will be executed only once – This is recommended for adjusting the MySites. Steve Peschka wrote a great blog post about this http://blogs.msdn.com/sharepoint/archive/2007/03/22/customizing-moss-2007-my-sites-within-the-enterprise.aspx
  3. You can use the ExecuteUrl element in the onet.xml. You can add a hyperlink to a custom aspx page to the ExecuteUrl. This page will be opened after the site is created. You can have the custom page make the changes you want to.
  4. You can create a custom provisioning provider, which adds the capability to hook custom code to be executed after the site has been created.

 

Print | posted @ Wednesday, April 29, 2009 3:14 PM

Comments on this entry:

Gravatar # re: Site Definition Provisioning Order
by Wictor at 4/29/2009 3:29 PM

Great post! I was thinking about this order this morning while troubleshooting some site def provisioning and could not find any (good) documentation/posts on the matter.
  
Gravatar # re: SharePoint Site Definition Provisioning Order
by Andy Burns at 5/1/2009 2:39 PM

Agreed - I was wondering about this yesterday, particularly the order of stapled features, and the modules.
  
Gravatar # re: SharePoint Site Definition Provisioning Order
by Serge van den Oever [Macaw] at 5/1/2009 2:48 PM

Great post, can keep people out of trouble!

Good old ExecuteUrl, was my "2003" way of doing modifications to a site after site creation. Problem is that it was only executed when you created a site from the Web UI, not when you create a site from code... I'm afraid that is still the case...
  
Gravatar # re: SharePoint Site Definition Provisioning Order
by Ayman El-Hattab at 5/4/2009 7:49 AM

Just wanted to point out that ExecuteUrl only works from create.aspx, in other words if you are creating a new site collection from the central administration, it's not gonna work :)
  
Gravatar # re: SharePoint Site Definition Provisioning Order
by Arshad at 4/21/2010 12:21 AM

How do I execute code after the site creation as part of the site definition(SD)? I need to do some operations on a list created from the <List> section of SD.
Thanks for any help.
  
Gravatar # re: SharePoint Site Definition Provisioning Order
by mirjam at 4/23/2010 2:41 PM

Hi Arshad,

The easiest way would be to use the ExecuteUrl element in the onet.xml, but you could use any one of the 4 options listed above.

  

Your comment:

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 3 and 6 and type the answer here: