Add to My Yahoo! | Google Reader or Homepage | Add to Windows Live | Add to Windows Live Alerts

Wictor Wilén

SharePoint Server MVP / Author / MCT / MCTS / MCP / MSc writing about SharePoint and other interesting Microsoft technologies

Create custom Rating icons for SharePoint 2010 Server

Posted at 2010-04-13 01:21 by Wictor Wilén in SharePoint 2010 with 5 comments.

SharePoint 2010 contains functionality for rating documents and items using a classic five-star rating approach. But those starts looks a little bit like the Google stars, right?

Wouldn't it be cool to brand the rating and use custom icons like this:

The solution is quite easy actually. You need to create a set of images and then set a few properties on the SPWeb object of the top-level site in the Site Collection.

Images

First you need four images. Two images used for CSS-sprites and two images used when hovering/selecting the rating. I used the following images:

This image is used for standard left-to-right rendering of the ratings.

This image is used for right-to-left rendering of the ratings.

|

And these final two images are used when selecting the new rating.

Deploy it as a feature

You should deploy everything as a feature, you should know this by now. Create an empty SharePoint 2010 project and add a new Site Collection scoped feature. Then add an Images mapped folder in which you add the four images.

Visual Studio 2010 solution

To set the properties of the TLS site in the Site Collection add a new Event Receiver to the feature. Edit the FeatureActivated method and add code like this:

SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = site.RootWeb;
web.AllProperties["ratings_imagestripurl_old"] = web.AllProperties["ratings_imagestripurl"];
web.AllProperties["ratings_imagestripurl"] = "/_layouts/Images/Wictor.CustomRatings/AlienRatings.png";
web.AllProperties["ratings_imagestriprtlurl_old"] = web.AllProperties["ratings_imagestriprtlurl"];
web.AllProperties["ratings_imagestriprtlurl"] = "/_layouts/Images/Wictor.CustomRatings/AlienRatingsRtl.png";
web.AllProperties["ratings_newratingiconurl_old"] = web.AllProperties["ratings_newratingiconurl"];
web.AllProperties["ratings_newratingiconurl"] = "/_layouts/Images/Wictor.CustomRatings/AlienRatingsNew.png";
web.AllProperties["ratings_emptyiconurl_old"] = web.AllProperties["ratings_emptyiconurl"];
web.AllProperties["ratings_emptyiconurl"] = "/_layouts/Images/Wictor.CustomRatings/AlienRatingsEmpty.png";
web.Update();

This will update the properties of the site and also save the original values so that we can restore them in the FeatureDeactivating method, like this:

SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = site.RootWeb;
web.AllProperties["ratings_imagestripurl"] = web.AllProperties["ratings_imagestripurl_old"];
web.AllProperties.Remove("ratings_imagestripurl_old");
web.AllProperties["ratings_imagestriprtlurl"] = web.AllProperties["ratings_imagestriprtlurl_old"];
web.AllProperties.Remove("ratings_imagestriprtlurl_old");
web.AllProperties["ratings_newratingiconurl"] = web.AllProperties["ratings_newratingiconurl_old"];
web.AllProperties.Remove("ratings_newratingiconurl_old");
web.AllProperties["ratings_emptyiconurl"] = web.AllProperties["ratings_emptyiconurl_old"];
web.AllProperties.Remove("ratings_emptyiconurl_old");
web.Update();

All you then have to do is to deploy and activate the feature. Unfortunately you need to recycle the application pool to get the hovering functions to work.

Comments and trackbacks

#  Sweet by Tobias Zimmergren [MVP]
Screenshot from websnpr Good overview Wictor. Though you could've picked some better icons, no? ;-)
#  @Zimmer by Wictor
Screenshot from websnpr Haha, no everyone wants Alien icons, right!
#  The World Runs on Software; SharePoint Development with Visual Studio 2010; Google Docs Promises Faster Service by Trackback
Screenshot from websnpr Top News Stories Sam Gazitt: SharePoint and Office Development with Visual Studio 2010 (Channel 9) Many
#  How to provision SharePoint 2010 Rating columns in Content Types by Trackback
Screenshot from websnpr This post continues in the same neighborhood as yesterdays post about provisioning Managed Metadata columns. This time we take a look at the Ratings in lists (and while we're at it check out another e...
#  How to provision SharePoint 2010 Rating columns in Content Types by Trackback
Screenshot from websnpr This post continues in the same neighborhood as yesterdays post about provisioning Managed Metadata columns
Make a comment on this post:
Subject:  

Your name:  
Your Url:  
Note: submissions may have to be approved before being visible, so don't submit your comment multiple times.
Real Time Web Analytics