tirsdag den 4. maj 2010

SharePoint 2010 custom stylesheet for standard list views

Custom List View XSL or how to change Add new item link to Add new umbrella link

Each time you create a list in SharePoint, you also create a List View web part that displays the content of the list. List View web parts works in the same way as all other web parts. You are able to pick a list view or change web part title. They are phenomenal, as long as you stay at the same site (web) as your list.
I noticed a new tab in the Tool Pane that opens when you select Edit Web Part. Aside from Appearance and Layout tabs, there is new Miscellaneous tab, and I was wondering for some time about a XSL Link property text box. It looks much like the ItemXslLink property for Content Query web part. I used ItemXslLink property to write a reference to another XSL file and override the standard link to ItemStyle.xsl file, stored in Style Library. I used to copy the content of the standard ItemStyle.xsl and create my own styles. My problem with List View and XSL Link was that List View web part doesn't link to XSL file that is stored somewhere on the portal. Well, everybody can create XSL file and upload it, but what is the chance that it will work. Zero, I think.
I got it to work though. There are easy three steps:
1. Get the standard XSL stylesheet
2. Upload the XSL stylesheet in Site Assets library and modify it
3. Configure the List View for your custom stylesheet

1. Get the standard XSL stylesheet:
- create a list in SharePoint 2010
- open the list in browser
- click on List tab in the ribbon and choose Modify View->Modify in SharePoint Designer.
- click on XsltListView web part in Design view
- click on Design tab in the ribbon
- click on Customize XSLT->Customize Entire View
- copy all the code starting and ending with xsl stylesheet tag

- open Notepad and paste the code
- save the file as ListView.xsl file

2. Upload the XSL stylesheet in Site Assets library and modify it
- open SharePoint 2010 portal in SPD
- click on Site Assets
- click on Import Files in the ribbon and upload ListView.xsl
- check out the ListView.xsl and open it
- locate 'Add new item' and change it to 'Add new umbrella'
- save and check in the file

3. Configure the List View for custom stylesheet
- add the ListView web part for yor list to the page
- click on the web part title and select Edit Web Part
- expand Miscellaneous tab
- write: /SiteAssets/ListView.xsl in XSL Link text box
- click on OK button to save the web part settings


Other Things I Wrote
Customize Content Query
Image Renditions in SharePoint 2013
The Story About SharePoint 2013
SharePoint 2013 JavaScript - Office Store App Licensing Script
Use ListView in SharePoint 2013 Apps