Add an XsltListViewWebPart to a site defintion homepage

3.8k Views Asked by At

What's the best method for adding an XsltListViewWebPart to a site definition's default.aspx?

I've tried to add one to the definition's default.aspx declaratively by copying the XML from an existing page, but there are a number of references to view and list guids which I won't have until the site is provisioned. The alternative was to programmatically add to the default.aspx via a site provisioned or feature activated event handler, but it's impossible to get a reference to the default.aspx until the site has been created.

1

There are 1 best solutions below

0
On BEST ANSWER

Add XML like this to your Module section:

<View List="$Resources:core,lists_Folder;/MyList" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="1" />

SharePoint 2010 will use the XsltListViewWebPart by default. You can still use the old ListViewWebPart with XML as follows:

<View List="$Resources:core,lists_Folder;/MyList" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="1">
    <![CDATA[
    <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
        <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
        <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
    </WebPart>
    ]]>
</View>