Handle Social(Rating&Liking) 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);
             
原文:http://www.sharepointcolumn.com/reputation-class-in-sharepoint-2013/?subscribe=invalid_email#blog_subscription-2
posted @ 2013-12-04 15:23  【上海】Peter  阅读(359)  评论(0)    收藏  举报