Thursday, 31 July 2014

Provisioning XsltListViewer web part in site definition / Issue with XsltListViewer web part order

Hi All,
Today sharing one small thing but interesting one. I learned this new thing so sharing J

Scenario: We have our custom site definition. We are provisioning instance of Link list in <Lists> element in site definition
We need to add XsltListViewer web part (XsltListViewWebPart) on front page for the above Link list. So we have module element to provision the front page and added XSLT Viewer web part having order 2. This module is added into web level feature and not in Onet.xml.

Problem: Whenever we were creating site this XsltListViewer web part appearing over the top means having order 0 for it. It’s not coming over the order mentioned for it, i.e. 2.

After doing lots of research it’s found that this is related to order of execution in Onet.xml. In following order parsing of Onet.xml happens:

  1. Site Features

  2. Stapled Site Features

  3. Web Features

  4. Stapled Web Features

  5. <Lists> element

  6. <Modules> element
Now, we are provisioning a page and web parts on it using web level feature so whenever page is provisioned, SharePoint trying to add XsltListViewer web part for the list which is not provisioned yet. <Lists> element executes after the <WebFeatures>.

But surprisingly SharePoint doesn’t throw an exception over there or doesn’t fail the site creation process but latter adds it as a top web part in the respective zone i.e. having order 0.

Possible approaches to avoid this kind of problem:

1.    Provision the list instance in web level feature and set the dependency of this feature over the feature which provision the pages.
    We used this approach and the web part is placed on correct order.
      2. Use the <Module> element from Onet.xml itself for provisioning the pages since 
          <module> element executes lastly. Till the time <Lists> are provisioned.


Enjoy reading J
Feel free to comment / feedback if any or if you have any query J

No comments: