In SharePoint 2010, Microsoft has introduced rating functionality for all lists. One of the most handy and requested features for publishing sites is for users have the ability to rate content. My clients usually want a 1 to 5 star rating scale and that is exactly what Microsoft has introduced.
For my purposes, I created a custom content type and page layout inherited from the OOTB article page layout. Within this page layout, I wanted the user to be able to rate the content on the page from a scale of 1 to 5. The first thing I did was enable ratings within my list settings by going to the /Pages/Forms/AllItems.aspx view and clicking on the Library Settings link on the Library tab of the ribbon:
The next thing I did was enable rating functionality on the list by going Rating Settings and checking the “Allow items in this list to be rated?” –> yes radio button:
What this did was add two new site columns/meta-data columns to my list called Number of Ratings and Rating (0-5):
Now, on my pages list, on the allitems.aspx view, it added a new rating field type web control associated with those columns:
This control is pretty cool, it has Ajax functionality and allows you to rate the item without checking out the list item (I’m not exactly sure how and where it stores the data yet):
You will notice that if you click a rating and then refresh the page, the rating actually disappears. What I found out here after reading this post [1] is that a timer job is run every hour that aggregates the ratings and calculates the average among other things. I didn’t want to wait an hour so I just went to the timer job called “User Profile Service Application – Social Rating Synchronization Job” (Central Admin –> Monitoring –> Review Job Definitions) and pressed the Run Now button. After a minute or so, the average rating showed up.
The next step was for me to add that star rating control to my page layout. Although I found many posts [2], that refer to it, I couldn’t find any that actually told me the control name so I found it using my favorite tool, .NET Reflector [3]. The control looks like this:
<SharePointPortalControls:AverageRatingFieldControl FieldName=”Rating_x0020__x0028_0_x002d_5_x0029_” runat=“server”/>
Just drop this control onto your page layout and change the fieldname to match your field name and there you have it.
To find the fieldname, I just opened up the allitems.aspx page in SharePoint designer and found the FieldRef that refers to a rating column:
<FieldRef Name=“Rating_x0020__x0028_0_x002d_5_x0029_” />
Now I have a rating control on my article content page layout which users can now use to rate:
Hope this helps you all.
Disclaimer: This was done on SharePoint 2010 beta
[2] http://weblogs.asp.net/bsimser/archive/2009/10/19/sharepoint-2010-what-s-new-ratings-spc09.aspx
[3] http://www.red-gate.com/products/reflector/