Create a custom list view with custom xsl in SharePoint 2010

To create a custom view with custom xsl, copy and paste the code below under <Views> element in your list schema with following changes –

1) Replace text under square brackets with your text. In the case of ‘BaseViewID’, make sure it’s not same as any other view in the list.

2) Make sure your custom xsl file is copied at 14hive/template/layouts/xsl. It’s the same location where you find main.xsl.

3) Replace the view fields in this xml to meet your requirements.

<View DisplayName=”[CustomListView]” BaseViewID=”[4]” DefaultView=”FALSE” Type=”HTML” MobileView=”TRUE” ImageUrl=”/_layouts/images/dlicon.png” WebPartZoneID=”Main” WebPartOrder=”1″ Url=”MyCustomListView.aspx” SetupPath=”pages\viewpage.aspx”>
        <XslLink>[Custom.xsl]</XslLink>
        <Query />
        <ViewFields>
          <FieldRef Name=”Title” />
          <FieldRef Name=”Description0″ />
          <FieldRef Name=”LinkFilename” />
          <FieldRef Name=”DocIcon” />
          <FieldRef Name=”Modified” />
          <FieldRef Name=”Editor” />
         <FieldRef Name=”_ModerationStatus” />
          <FieldRef Name=”FileRef” />
        </ViewFields>
        <RowLimit Paged=”TRUE”>30</RowLimit>
      </View>

Alternatively, you can also do this to get view schema –

1) In your SP Site, create custom view in your list as close as possible to the actual requirement. Save this site as site template. It will create a wsp in solutions gallery.

2) Export this wsp file from Solution gallery.

3) Open Visual studio and create a project of sharepoint type ‘Import Reusable package’ and import exported wsp. This will open all the site components such as lists, doclibs etc in project.

4) Look for your list in this project. Copy and paste the view schema in to your actual list definition.

 

Trackbacks

Leave a Comment

Your email address will not be published. Required fields are marked *