0

I am trying to get the current logged in user rating for items in document libraries . However. It is giving rating as 0 for the all the documents. I am using below code

SPSite site = new SPSite(SPContext.Current.Web.Url);
        {
                    SPWeb web = site.OpenWeb();
                    {

  string fileUri = "http://..." + webUrlSplit;

  Uri urifileUrl = new Uri(fileUri);

   SPServiceContext context = SPServiceContext.GetContext(site);

   SocialRatingManager mySocialRatingManager = new SocialRatingManager(context);

   SocialRating aRating = mySocialRatingManager.GetRating(urifileUrl);

    string myRating = aRating.Url + ": " + aRating.Rating;                       

    objtopRated.myRating = myRating;

}

}

In the above code fileUri is the docuemnt url of the item in doc library

eg. someSiteUrl/ProductsandPricing/Pricing/Pricing_Document 1.xlsx

I referred the below msdn link

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

1 Answer 1

0

SocialRatingManager.GetRating method accepts absolute URL as a parameter

public SocialRating GetRating(
    Uri url
)

To construct Uri for the List Item the following code could be used:

var itemUrl = new Uri(SPUrlUtility.CombineUrl(web.Url, item.Url));
1
  • Thanks for the quick answer...However,currently I am passing absolute ur only like http:// sp2013/ProductsandPricing/Pricing/Pricing_Document 1.xlsx
    – Rameez
    Commented Mar 27, 2014 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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