<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>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages2 Page
-
File Size-