1

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?

1

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);
}
| improve this answer | |
1

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

| 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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