Saturday 28 November 2015

"Views Likes Comments" in SharePoint 2010.


A month ago, I got a task to design functionality that provides Facebook features such as views, likes, and comments in SharePoint 2010 for our intranet portal.

In SharePoint 2010, there is no way to get such functionality out-of-the-box, but SharePoint 2013 provides it out-of-the-box.

I have created a simple SharePoint webpart to implement the functionality.

Steps to implement are:
1. Create a farm solution and add a web part.



2. Add the feature event receiver, constants, and CustomList file, and add the required images under the mapped image folder. The structure should be similar to that shown below (use standard naming conventions).


3. On the FeatureActivated method, call CustomList methods to create a list and add site columns to it.

4. Add a constants entry in the constants.cs.

5. In the webpart, add child controls for views, comments, and likes. And on page load event query the view count, comment count, comments, and like count from the lists..

6. Deploy the solution and activate the feature.


7. Edit the page and add a webpart to it as given below.


8. The page will look like this with a view count.

9. Click on "Like" to like the page. Here I have used the REST API of SharePoint 2010 using a list.svc you can find it in "like-newsArticle.js". There is a feature of like and unlike, and accordingly, the icon will change.


10. Then an entry will be added to the list - "Record Data List".


11. Click on the comments icon, then a div will slide down to enter, and press the comment button again. A REST query is used to save the data.


12. The comments entry will be saved into the list - "RecordDataCommentsList".


13. The final output is like this:


14. You can also edit the comments.


The views count is done on a per-user, per-page, per-day basis. If you refresh the page, the count will not increase.
The "Approve", "Edit" and "Reply" methods are now not implemented, but you can extend the functionality according to your use and needs.

I have uploaded the latest Visual Studio 2010 solution Likes.Comments.Views.REC.7z


🚀 "Happy Coding" 🚀