Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm working on rating feature for our SharePoint application. I have a custom list something like below: ex.

UserId -- Title -- JobId -- Rating(0-5) -- Number of Ratings

UserId & JobId together makes unique key.

Basically, I have to read rating values and create aggregate and display in UI. So, in my application page I need to read these 'Rating' & 'Number of Ratings' field values.

Can any one please suggest how to do this?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

In order to retrieve the rating for list item use the following method:

public SocialRating GetRating(
    Uri url
)

exposed by class SocialRatingManager

To construct Uri for the list item the following code could be used:

var itemUrl = new Uri(SPUrlUtility.CombineUrl(web.Url, item.Url));

The following example demonstrates how to retrieve Social Ratings for list item:

private static SocialRating GetListItemSocialRatings(SPWeb web, SPListItem item)
{
    var context = SPServiceContext.GetContext(web.Site);
    var socialRatingManager = new SocialRatingManager(context);

    var itemUrl = new Uri(SPUrlUtility.CombineUrl(web.Url, item.Url));
    return socialRatingManager.GetRating(itemUrl);
}
share|improve this answer

Once you have URI of the item, it's easy to read rating for a list item. Check the link below

http://msdn.microsoft.com/en-us/library/ff407954.aspx

And

SocialRatingManager Members

share|improve this answer
    
This one is good. Could you suggest me how to find/get the uri for items in a custom list. –  sandeep talabathula Jan 30 '12 at 19:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.