I have a usercontrol and inside its ascx.cs file I would like to do a check(if) if current user is following the current site.

How can I accomplish that?

So far I have done something like this:

SPSite currentSite = SPContext.Current.Site;
            SPServiceContext context = SPServiceContext.GetContext(currentSite);
            var currentUser = SPContext.Current.Web.CurrentUser.LoginName;
            var profile = new UserProfileManager(context);
            var user = profile.GetUserProfile(currentUser);
            SPSocialFollowingManager followingManager = new SPSocialFollowingManager(user, context);

SPSocialFollowingManager have a method called IsFollowed() which determines whether the current user is following the specified actor.

I guess that I need to use that one?

Any kind of help is appreciated


You are on the right track. See the following code:

SPSocialActorInfo actorInfo = new SPSocialActorInfo();
actorInfo.ActorType = SPSocialActorType.Site;
actorInfo.ContentUri = new Uri(SPContext.Current.Url);

bool doesCurrentUserFollowCurrentSite = followingManager.IsFollowed(actorInfo);
  • Thank you! Is that all that is required? Or do I need to have any of my code in your code snippit aswell? – Rohander Jul 31 '13 at 13:45
  • Yup this snippet will run after your code – Vardhaman Deshpande Jul 31 '13 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.