Part of the new SharePoint 2010 social features are item ratings, which allow users to rate documents or list items in a scale between 1 and 5. This is achieved with the help of two fields; the Rating and Number of ratings. The rating field shows the average rating in a 5-star format while the number of ratings holds how many times the specific item has been rated. Important to mention that Office 2010 clients can render the 5 stars just fine. That’s not all, the ratings are processed by a timer job: Social Rating Synchronization Job and note that you will require a User Profile Service provisioned. Your ratings will appear out of date until the timer job executes and completes. You can always reduce the timer job interval to suit your needs – even though this can impact your farm’s performance.

image

  Now lets shift over to development. Enabling ratings on a list isn’t that complicated, but I think the SharePoint team could of made it a bit more elegant. First of all you need to enable the Ratings Feature at the site collection level. The feature has an ID of 915c240e-a6cc-49b8-8b2c-0bff8b553ed3. Now that we have our two columns, we just need to add them to the list.

The two fields are:

Static Name ID Description
AverageRating
5a14d1ab-1513-48c7-97b3-657a5ba6c742
Renders the interactive 5 stars
RatingCount
b1996002-9167-45e5-a4df-b2c41c6723c7
Holds how many times the item has been rated.

  Simply add the two fields to a list and all the content types it uses – if any. One way will be to create an event receiver that listens to the List Added event and then simply add the two ratings columns to the list programmatically.

Advertisements