How to Create a Visual Webpart in Sharepoint 2013 to Suggest People to Follow?

How to Create a Visual Webpart in Sharepoint 2013 to Suggest People to Follow?

<p>How to create a visual webpart in SharePoint 2013 to suggest people to follow?</p><p>1) Initially we need to create user profile object of the logged in user.</p><p>//Get the UserProfile for target user SPUser us = SPContext.Current.Web.CurrentUser; SPSocialFollowingManager _followManager=null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite elevatedSite = new SPSite(SPContext.Current.Web.Url)) { SPServiceContext serverContext = SPServiceContext.GetContext(SPContext.Current.Site); UserProfileManager profileManager = new UserProfileManager(serverContext); UserProfile profile = profileManager.GetUserProfile(us.LoginName); if (profile != null) { //Create a Social Manager profile _followManager = new SPSocialFollowingManager(profile); } } });</p><p>Once we get the user profile of the current logged in user, we need to create socialfollowingmanager of the current user.</p><p>SPSocialFollowingManager Class can be created using Microsoft.Office.Server.Social namespace.</p><p>2) Once we get the socialfollowingmanager of the current user, we can retrieve the followers of the current user as well as people whom the current user is following using the following methods accordingly-  _followManager.GetFollowers();  _followManager.GetFollowed(SPSocialActorTypes.Users); //Here we need to pass the entity</p><p>3) Once we get the followers and followed people, we can find the common people whom the current user is not following, and for the current user we can suggest those people to follow SPSocialActor[] actors = _followManager.GetFollowers(); SPSocialActor[] ifollow = _followManager.GetFollowed(SPSocialActorTypes.Users);</p><p>We can then iterate through the followers and check whether the current user is following the user, if not we can suggest that user to follow foreach (SPSocialActor follower in actors) { actorInfo = new SPSocialActorInfo(); actorInfo.AccountName = follower.AccountName; actorInfo.ActorType = SPSocialActorType.User; if (!_followManager.IsFollowed(actorInfo)) { <<We can suggest this user to follow>> }</p><p>We can also iterate through the followers of that user and do the same check and accordingly suggest users.</p><p> profilesecond = profileManager.GetUserProfile(follower.AccountName); if (profilesecond != null) { SPSocialFollowingManager _followManagersecond = new SPSocialFollowingManager(profilesecond); SPSocialActor[] secondfollowers = _followManagersecond.GetFollowers(); if (secondfollowers.Length > 0) { foreach (SPSocialActor secondactor in secondfollowers) { actorInfo = new SPSocialActorInfo(); actorInfo.AccountName = secondactor.AccountName; actorInfo.ActorType = SPSocialActorType.User; if (!_followManager.IsFollowed(actorInfo)) { <<We can suggest this user to follow>> }</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us