Rez's SharePoint Blog Spot

:


Add me to LinkedIn   RSS Feed   Follow me on Twitter
Rez's SharePoint Blog Spot > Posts > Adding rating ability to a SharePoint 2010 publishing page layout
November 30
Adding rating ability to a SharePoint 2010 publishing page layout

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:

 image

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:

image

What this did was add two new site columns/meta-data columns to my list called Number of Ratings and Rating (0-5):

image

Now, on my pages list, on the allitems.aspx view, it added a new rating field type web control associated with those columns:

image

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):

image

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.

image

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:

image

Hope this helps you all.

Disclaimer: This was done on SharePoint 2010 beta

[1] http://blogs.technet.com/speschka/archive/2009/10/28/using-the-new-sharepoint-2010-ratings-feature-in-search.aspx

[2] http://weblogs.asp.net/bsimser/archive/2009/10/19/sharepoint-2010-what-s-new-ratings-spc09.aspx

http://www.andrewconnell.com/blog/archive/2009/10/19/part-3-whats-new-with-sharepoint-server-2010-web.aspx

[3] http://www.red-gate.com/products/reflector/

 

Comments

Error: unknown server tag

Hi, thanks for the post.  I was looking for the exact same information, however this did not work for me.  When I used your code, I get the squiggly line in Designer 2010 and then on the page I get the following error:

Unknown server tag 'SharePointPortalControls:AverageRatingFieldControl'.

The log file with the corresponding correlation ID wasn't any more useful:

System.Web.HttpException: Unknown server tag 'SharePointPortalControls:AverageRatingFieldControl'.    at System.Web.UI.TemplateParser.ProcessError(String message)     at System.Web.UI.TemplateParser.ProcessBeginTag(Match match, String inputText)     at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)   

Any ideas?  I can see and rate the files from the regular list view, so the feature seems to be installed and working correctly. 

Thanks for your help!

-Peter
 on 12/21/2009 1:29 PM

Re: Error: unknown server tag

You are probably missing a page reference in your page to the assembly that the AverageRatingFieldControl is in.  I'll see if I can look it up tomorrow.
Noorez KhamisNo presence information on 12/22/2009 6:09 PM

Re: Error: unknown server tag

Thanks, you were right, all I needed was to add the page reference at the top of the page.  This was the extra line of code that worked for me:

<%@ Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


Thanks again!

-Peter

 on 12/28/2009 10:25 AM

How to display rating on the individual blog post

Hi i have a requirement like this:
 
I have to add the rating control in the Post.aspx page in the blog site.. The List 'Post' contains the rating control but i dont know how to get this rating control in the post.aspx page which displays a single post from the 'Post' List.
 on 2/25/2010 4:12 AM

No User Profile Application available to service the request. Contact your farm administrator.

Thanks for the great post.
 
I seem to get the following error message when attempting to switch Rating on for a Document Library:
 
"No User Profile Application available to service the request. Contact your farm administrator. "
 
Have you encountered this before?
 on 3/3/2010 4:57 AM

Rating in a custom webpart

Hi,
nice post. I have a question. It's possible to use this control in a custom webpart and set rating value using something like a property?
In my mind I would to present aggreate data from a document library (like pages) in a web part and report the rating for each content. I create my domain using SPMetal and I get AverageRating value using it. Now, unfortunately, I don't know how to assign it to the AverageRatingFieldControl in my webpart. Any suggestions?
Thanks

Simone
 on 3/10/2010 6:31 AM

item is currently unrated

i followed all steps.
I have created a discussion and apply rating to it.
i can see the rating control now, but  it is not retriving the value of each post/reply. Also if i am trying to rate it. it shows message 'item is currently unrated. Press SHIFT +ENTER to enter rating'.
and its not wrking too... 
what is data type of rating column? is it int/decimal??
 
 on 4/13/2010 3:02 AM

follow this steps to rate

i have copied the tag for rating control from wiki page, if you open wiki page in designer you wil get rating field in sharepoint contents field section. copy and paste that code in article page in designer.. it will work like charm.. :-)
 
 on 5/18/2010 1:47 AM

Correct field name in RTM

The "Rating ( 0 - 5 ) (list column name) doesnt work in RTM.

Use AverateRating instead:

     <SharePointPortalControls:AverageRatingFieldControl ID="PageRatingControl" FieldName="AverageRating" runat="server"/><br />

 on 8/2/2010 7:04 AM

Re: Adding rating ability to a SharePoint 2010 publishing page layout

Great post Noorez! I got following error message when attempting to switch Rating on for a Document Library? Have you ever encountered this before? Thanks in advance..
 on 11/19/2010 12:22 AM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Name


Your URL


Comments *

SPAMMER Skill Testing Question - What is 2x3? *


This field is to protect me against the barrage of spammers

Attachments