Adding XsltListViewWebPart to a Homepage (landing-page) in Site Definition and Setting the Web Part Display Properties


Read It

Have you ever tried add a XsltListViewWebPart to display a list view (e.g. “My Project Tasks” or “My Issues”) to the default landing page of your site and unable to change the title of the webpart, frame type etc. as the code differs from that of a standard web part?

You may have tried this by declaratively copying the XML from an existing page after a customization but still no luck.

Let’s Fix

The following declaration shows how you can use the “ListViewWebPart” to accomplish this (I presume, most of you’ll familiar with the view declaration):

<View List="$Resources:BflResource,ldiv_lists_Folder;/$Resources:BflResource,ldiv_projectTask_Folder;" MobileView="TRUE" MobileDefaultView="TRUE" Type="HTML" Url="$Resources:BflResource,ldiv_lists_Folder;/$Resources:BflResource,ldiv_projectTask_Folder;/MyItems.aspx" BaseViewID="2" ImageUrl="/_layouts/images/issuelst.png" WebPartZoneID="Right" WebPartOrder="1">
          <XslLink Default="TRUE">main.xsl</XslLink>
          <RowLimit Paged="TRUE">15</RowLimit>
          <Toolbar Type="Standard" />
         <ViewFields>
            <FieldRef Name="LinkTitle" />
            <FieldRef Name="StartDate" />
            <FieldRef Name="DueDate" />
            <FieldRef Name="PercentComplete" />
            <FieldRef Name="Status" />
            <FieldRef Name="Priority" />
            <FieldRef Name="Predecessors" />
          </ViewFields>
          <Query>
            <Where>
              <Eq>
                <FieldRef Name="AssignedTo" />
                <Value Type="Integer">
                  <UserID />
                </Value>
              </Eq>
            </Where>
            <OrderBy>
              <FieldRef Name="Status" />
              <FieldRef Name="Priority" />
            </OrderBy>
          </Query>
        <![CDATA[
        <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2"&gt;
          <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
          </Assembly>        
       <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
          <Title>$Resources:core,My_Tasks;</Title>        
          <FrameState>Normal</FrameState>
          <AllowRemove>true</AllowRemove>
          <AllowZoneChange>true</AllowZoneChange>
          <AllowMinimize>true</AllowMinimize>
          <AllowConnect>true</AllowConnect>
          <AllowEdit>true</AllowEdit>
          <AllowHide>true</AllowHide>
          <IsVisible>true</IsVisible>
          <MissingAssembly>$Resources:core,ImportErrorMessage;</MissingAssembly>
        </WebPart>
        ]]>
      </View>

Finally

Related references:

http://stackoverflow.com/questions/4156014/add-an-xsltlistviewwebpart-to-a-site-defintion-homepage
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.xsltlistviewwebpart.aspx
http://stefan-stanev-sharepoint-blog.blogspot.com/2010/06/sharepoint-2010-binaryserializedwebpart.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.