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.