Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Programmatically retrieve social ratings in sharepoint 2010

Programmatically retrieve social ratings in sharepoint 2010

Here is an example of how to retrieve social ratings

Using Object model -

string GetRatingForThisURL = “http://MySharePoint/Pages/NewWebPart.aspx”;

Uri myUri = new Uri(GetRatingForThisURL);
using (SPSite site = new SPSite(“http:/SharePointSite”))
{
SPServiceContext context = SPServiceContext.GetContext(site);
SocialRatingManager mySocialRatingManager = new SocialRatingManager(context);
SocialRating aRating = mySocialRatingManager.GetRating(myUri);
Console.WriteLine(aRating.Url + “: ” + aRating.Rating);
}

Using WebService -

string GetRatingForThisURL = “http://MySharePoint/Pages/NewWebPart.aspx”;

ServiceReference1.SocialDataService mySocialDataService = new ServiceReference1.SocialDataService();
mySocialDataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
mySocialDataService.Url = “http://MySharePoint/_vti_bin/socialdataservice.asmx”;
SocialRatingDetail details = mySocialDataService.GetRatingOnUrl(GetRatingForThisURL);
Console.Write(“The rating for ” + GetRatingForThisURL + ” is ” + details.Rating.ToString());
Console.Read();

No comments:

Post a Comment