Domanda

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?

È stato utile?

Soluzione

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);
}

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top