How To Use Ratings In Lists And Libraries Using Rating Settings, Server Side Coding And PowerShell Commands

In this article I will discuss how to make use of ratings to your lists & libraries. Ratings are the features introduced by Microsoft which allow users to evaluate & rate the authors. Here I will explain how to use ratings on the lists & libraries.

So let’s get started.

In order to allow library visitors and contributors to rate library items, and to encourage interaction, ratings must be turned on for the library. Follow below steps to activate the Rating feature to manage list and library in SharePoint Online:-

Step 1

Create a “Document Library” inside your Team Site.

Note

For creating a Document Library refer my previous article where I have mentioned “Sample Document Management System”.

 Refer to the below screenshot,

PowerShell

Step 2

Click on “Library” tab & select “Library Settings” option present on the top below screen will appear. Refer to the below screenshot,

PowerShell
PowerShell

Step 3

Go to “General Settings” & select “Rating Settings”. Refer to the below screenshot,

PowerShell

Step 4

Select the “Rating Settings” option to “Yes” and choose rating experience as “Star Rating” or “Likes” and click Ok. Refer to the below screenshot,

PowerShell

Step 5

Three new columns will be created as Rating (0-5), Number of Ratings and Number of Likes. Refer below screenshot,

PowerShell

Step 6

We have to check these three columns. For this go to your respective Document library and click on “Library” tab & select “Modify View”. Refer to the below screenshot,

PowerShell

Step 7

Check the “Ratings (0-5)” Checkbox and the column will appear in the document library. Refer to the below screenshot,

PowerShell

PowerShell

Step 8

To rate the documents upload a document & simply hover your mouse on the “Rating (0-5)”column. Refer to the below screenshot,

PowerShell

OR,

This can be achieved by using Server Side Coding. Follow below steps,

Step 1

Add dll as “Microsoft.SharePoint.Portal.dll”.

Step 2

Make changes to “Enable Rating” & “Disable Rating” Methods. Refer to the below screenshot,

  1. //Enable Rating  
  2. publicstatic void enableRating(SPList oList)  
  3. {  
  4.     Type type = typeof(Microsoft.SharePoint.Portal.RatingsSettingsPage);  
  5.     MethodInfo mi = type.GetMethod("EnableRatings", Static | BindingFlags.NonPublic);  
  6.     Invoke(null, newobject[]  
  7.      {  
  8.         oList,  
  9.         false  
  10.     });  
  11. }  
  12. //Disable Rating  
  13. publicstaticvoid disableRating(SPList oList)  
  14. {  
  15.     Type type = typeof(Microsoft.SharePoint.Portal.RatingsSettingsPage);  
  16.     MethodInfo mi = type.GetMethod("DisableRatings", Static | BindingFlags.NonPublic);  
  17.     Invoke(null, newobject[]  
  18.     {  
  19.         oList  
  20.     });  
  21. }  
OR,

 

We can use PowerShell script to use ratings in our lists & libraries. Refer to the below screenshot,

  1. Add - PSSnapin "Microsoft.SharePoint.PowerShell" - ErrorAction SilentlyContinue  
  2. $web = Get - SPWeb "http://abc.com/test";  
  3. $list = $web.Lists["Pages"];  
  4. if ($list - ne $null)   
  5. {  
  6.     Write - Host $list.Title "not null";  
  7.     $assembly = [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")  
  8.     $reputationHelper = $assembly.GetType("Microsoft.SharePoint.Portal.ReputationHelper");  
  9.     $bindings = @("EnableReputation""NonPublic""Static");  
  10.     [System.Reflection.BindingFlags] $flags = [System.Reflection.BindingFlags]::Static - bor[System.Reflection.BindingFlags]::NonPublic;  
  11.     $methodInfo = $reputationHelper.GetMethod("EnableReputation", $flags);  
  12.     #For enabling Ratings  
  13.     $values = @($list, "Ratings", $false);  
  14.     #OR  
  15.     for enabling Likes# $values = @($list, "Likes", $false);  
  16.     $methodInfo.Invoke($null, @($values));  
  17.     #For disable Rating or Likes <   
  18.     #  
  19.     $methodInfo = $reputationHelper.GetMethod("DisableReputation", $flags);  
  20.     $disableValues = @($list);  
  21.     $methodInfo.Invoke($null, @($disableValues));  
  22.   # >  
  23. }  
So these are the processes through which we can achieve ratings in respective Lists or Libraries.

 

Up Next
    Ebook Download
    View all
    Learn
    View all