Raghu's SharePoint Column : SharePoint - My Lifeline!!

Raghu's SharePoint Column

Reputation Class in SharePoint 2013

SharePoint 2013 provides a new namespace called Reputation Model.  The classes available in this namespace can be used to perform operation like Rating and Like on a SharePoint List Item in SharePoint 2013 using Object Model.

Note: If you are planning to use this in object model makes sure you have enabled Rating/Like Feature on the list.

Assembly: Microsoft.Office.Server.UserProfiles.dll

You can access these class methods by adding Microsoft.Office.Server.UserProfiles.dll as a reference in your project

Class: Following are the classes which are available with the namespace

  1. Reputation
  2. ElevatedPrivilegesHelper

While exploring Reputation class I have come across the below two method.

Methods in Reputation Class:

1.       SetLike:  This method takes 3 input parameters

  •  ListID as string – List id of the list in which the item exist
  • ItemID as Int – list item which need be liked
  • Like as bool – Pass the value true if you like the item or false for unlike

 Sample Code for performing Like Programmatically using C#

              SPList resourceList = SPContext.Current.Web.Lists["Resources"];
              SPListItem likeItem = resourceList.Items[0];
              Reputation.SetLike(resourceList.ID.ToString(), likeItem.ID, true);
              

 2.       SetRating:  This method takes 3 input parameters

  • ListID as string – List id of the list in which the item exist
  • ItemID as Int – list item which need be liked
  • Rating as bool – You can pass value from 1 to 5

 Sample code for performing a Rating operation using Object Model

              SPList resourceList = SPContext.Current.Web.Lists["Resources"];
              SPListItem likeItem = resourceList.Items[0];
              Reputation.SetRating(resourceList.ID.ToString(), likeItem.ID, 4);
             

I am still exploring the classes available in this namespace and will update the post accordingly if i find any valuable info :)

 
Comments

No comments yet.

Leave a Reply
*

Protected by WP Anti Spam