Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to create a site definition using webtemp*.xml and onet.xml. I am creating all my list instances through onet.xml only. I have a feature which I am using to manipulate a list in this site. I have this feature activated through the <sitefeatures> element in onet.xml. But when I try to create a site using this definition, everything works fine except the feature activation code. The activation code throws me an error - "Value does not fall within the expected range". On further investigating, I found that this is because the list instances are created only after the Site-scoped features and Web-scoped Features are activated and hence in my feature code when I am trying to fetch a particular list, I encounter this error. Could anyone help me out on this. I want the feature to be activated and code to be executed once the site is created through this definition.
Posted

1 solution

Hi all,
I just got the solution for this.
I did a research on this and found that the reason for the error being thrown is the order in which elements are provisioned through the definition in onet. SharePoint provisions in the following order:
1)global onet.xml
2)SPSite scoped features defined in onet.xml, in the order they are defined in the file.
3)SPSite scoped stapled features, in quasi random order
4)SPWeb scoped features defined in onet.xml, in the order they are defined in the file.
5)SPWeb scoped stapled features, in quasi random order
6)List instances defined in onet.xml
7)Modules defined in onet.xml

Reference : http://blogs.msdn.com/b/mcsnoiwb/archive/2008/05/28/site-provisioning-order.aspx[^]

And since lists are created only after the Site and Web scoped features are provisioned, my feature code does not get the list it is searching for and hence throws the exception.
A work around to this solution that I have found out is -
First create a feature which will provision all your lists and through list instances.
Then activate the feature that is looking for the list (the feature which is throwing the error.)
I have tried this and it is working fine.

Another suggested work around that was found is creating the site definition using the SPWebProvisioningProvider class.
Please refer the link below -

http://blogs.technet.com/b/apurdon/archive/2008/02/05/the-mystery-that-is-spwebprovisioningprovider.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900