Branding Shared Document Library using XSLT in SharePoint 2010 step by step
While
working on SharePoint Portal I faced urgent need for document library
Very
much like out of the box SharePoint document library and same functionality
But
the problem how I can style it and gain benefits from all great functionality
it has.
I
know there is different ways by styling the XSLT from SharePoint Designer and
apply inline style for items but unfortunately some time SharePoint designer doesn't persist changes and sometimes it’s show you unclear error messages.
To
solve the problem and make my changes persist I used Visual studio 2010 and
SharePoint Designer 2010 and follow the pattern of trial and error till I get
the solution I am looking for.
I
used IE developer tool to see the CSS class name that XSLT control render then
going back to XSLT and try to find the same class name.
The
solution file (click here to download) contain
- XSLT file (customDocLibaray.xslt)
- CSS file (CustomDocumentLibrary.css)
I
will use Visual studio 2010 and SharePoint 2010
Visual Studio 2010
- Create Empty SharePoint 2010 Project (XSLT-SharedDocument) or download.
- Adding Mapped Folder to XSL (Template / Layouts/XSL)
- Add XSLT file customDocLibaray.xslt
- Delete everything from the file (customDocLibaray.xslt)
SharePoint 2010
- Go the Web site (http://xxx/)
- Open the Shared Document Library in Web Browser
- Using Library settings create slandered view :
- View Name : CustomLibaray
- Select the following Column:
- Type (icon linked to document)
- File Size
- Name (linked to document)
- From Tabular view section uncheck (Allow individual item checkboxes)
- From section item limit enter 5 for the number of items … this for my case , you can enter any number as you wish
- After creating the view you get custom view for shared document library as below image:
From the menu select Edit Web
Part , a new window appear select the view we already create (CustomLibaray)
after selecting the view your web Part page will look like the below image
No we want start
branding the Shared Document Library using SharePoint Designer 2010
- Open you site (http://xxx) using SharePoint Designer 2010
- From Lists and Libraries select Shared Document Library then from views select CustomLibaray
- Right click Edit File in Advanced mode
- Designer will open the view
- From designer select the tag WebPartPages:XsltListViewWebPart as shown in image below
- Then from Design Tap in top Menu in SharePoint Designer 2010 select the menu Customize XSLT then Select Customize the Entire View as shown in image bellow
- From code behind remove all ddwrt:ghost="hide" since it’s prevent persistence changes on XSLT.
- On Designer select file size tag then click edit tag as shown in image bellow ,change the class ms-vh-div to class header-div
- And do the same
for other headers (Name and Type).
- click on edit tag for header TD as bellow image:
- And do the same for other header cell.
Sometimes Changing the TD class on designer will
not persist the changes for that you have to change it from code file XSLT.
to avoid the persistence problem open the Code File XSLT and follow below instructions:
- Replace all vh-ms and vh-ms2 with value header-td
- In header row using designer change the class for header row by replacing class="{concat('ms-viewheadertr',$dirClass)}" with value class="header-row"
- Replace ms-itmhover with rowhover
- Finally Find the following section<xsl:when test="$Position mod 2 = 0">ms-alternating</xsl:when><xsl:otherwise></xsl:otherwise> And replace it with <xsl:when test="$Position mod 2 = 0">alternaterow</xsl:when><xsl:otherwise>row</xsl:otherwise>Here we add css class for row and for alternate row.
Summary:
You have to replace the following classes in XSLT file:
- header-div replacement for ms-vh-div
- header-td replacement for ms-vh2 and ms-vh
- row-hover replacement for rowhover
- alternaterow replacement for ms-alternating
- row is new class I add it to the gain more control on CSS
- if you want change (here I did not change anything) the Pager Style you can replace the following CSS classes:
- ms-bottompaging
- ms-bottompagingline1
- ms-bottompagingline2
Final Steps:
- Copy and Paste the <xsl:stylesheet tag from SharePoint Designer to the file customDocLibaray.xslt in visual studio
- Deploy solution
- Go back to your site (http://xxx)
- Edit the web Part Shared Documents
- From Selected view select : CustomLibary
- From Miscellaneous category add the link for your XSLT file (http://xxx/_LAYOUTS/XSL/customDocLibaray.xslt)
- Add the css file (CustomberDocumentLibaray.css) to style library of your application then from site settings apply it as below image
You will get this fully function Document Library:
I hope that you find it useful.
Any comment or question is more than welcomed.
and about document location i.e. link to folder? Have you a good idea how to do it?
ReplyDeletewhat do you mean by link to folder,
Deleteit's already link-able and when you click it's working
this is what u mean?