Introduction
SharePoint 2013 comes with so many new features, one of which is to set the rating in the document library. This is very useful for document management and filtering documents by most ratings.
Solution:
SharePoint provides an easy out of the box way to enable this setting in Document Library. You can do it by going to Document Library setting, under general setting look for Rating setting. To enable rating check “Allow items in this list to be rated” to Yes. SharePoint also provide an option to choose Like/ Dislike option or star rating.

Now we will see how to achieve the same thing programmatically.
The following code snippet enable Like/Rating in Document Library
- using system.Reflection;
- using Microsoft.SharePoint;
- public static void EnableRating(SPList oLibrary)
- {
- Assembly assembly = Assembly.Load("Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
- Type reputationHelper = assembly.GetType("Microsoft.SharePoint.Portal.ReputationHelper");
- MethodInfodisableRatingMethod = reputationHelper.GetMethod("DisableReputation", BindingFlags.Static | BindingFlags.NonPublic);
- disableRatingMethod.Invoke(null, new Object[]
- {
- oLibrary
- });
- MethodInfoenableRatingMethod = reputationHelper.GetMethod("EnableReputation", BindingFlags.Static | BindingFlags.NonPublic);
- // "Likes" or "Ratings" as per your requirement.
- enableRatingMethod.Invoke(null, new Object[]
- {
- oLibrary,
- "Ratings",
- false
- });
- oLibrary.Update();
- }

Code Explanation
Assembly.Load method loads the dll dynamically in the application, it takes the four parameters, name of the dll you want to load, its version number culture and publiscKeyToken. reputationHelper is the class which is coming from Microsoft.SharePoint.Portal assembly. There are multiple ways to call a method in the class. GetMethod method is used for getting the methods dynamically. We are calling thee DisableReputation and EnableReputation methods to toggle the rating settings in the Document library.
BindingFlag.Static means the Disable Reputation method is a static method and it is non-public method.
Enable rating is executed by calling execute method. If the method has parameter, it has to be passed as object array. First is the Library object, and then the type of rating you want to enable either Like or Ratings. If you select Like then you get the vote option and if you select the rating, rating setting gets enabled.


Humayun Kabir MamunPosted Mar 12, 2016, 10:18 PM EST
Nice...
Prashant VermaPosted Mar 11, 2016, 11:36 PM EST
thanks
Sibeesh VenuTOP 100Posted Mar 10, 2016, 11:46 PM EST
Nice Share
Mohammed IbrahimPosted Mar 10, 2016, 5:18 AM EST
nice
Vignesh ManiTOP 100Posted Mar 9, 2016, 11:13 PM EST
nice
Sagar PardeshiPosted Mar 9, 2016, 10:24 PM EST
Nice Article...