2

I haven't found that much information online about how to utilize the Social Part of SharePoint 2013 by Server Object Model. To understand and follow my question better i recommend you going to this site.

Lets say I have a Feature Receiver that is fired when i certain site is created and I would like to take advantage of the Follow Content Feature but instead of every time a site is created i would like to make the person that created the site automatically follow that site.

Does anyone got experience with working with the Social functionallity in SharePoint 2013? If so would be awesome with a summary how to use the different Social methods.

Social Actor

From what I've understood from reading about this you need to create a "Actor" to represent the item or in my case the site. SocialActorInfo which takes to properties ContentUri and ActorType.

SocialActorInfo actorInfo = new SocialActorInfo();
actorInfo.ContentUri = contentUrl;
actorInfo.ActorType = contentType;

Find and Check if that Actor is followed by the current user

Then you have to check if that SocialActor is Followed by the current user.

ClientResult<bool> isFollowed = followingManager.IsFollowed(actorInfo);

Follow/Unfollow the Site/Item

 ClientResult<SocialFollowResult> result = followingManager.Follow(actorInfo);
 clientContext.ExecuteQuery();

 "followingManager.UnFollow(actorInfo);"

Questions,

If I want to follow a site, what kind of ActorTypes are there?

How do i do this with server-side code?

Additional Information

Microsoft says: When users follow documents, sites, or tags, status updates from documents, conversations on sites, and notifications of tag use show up in their newsfeed. The features related to following content can be seen on the Newsfeed and the Following content pages.

SharePoint Server 2013 provides the following APIs that you can use to programmatically follow content:

  • Client object models for managed code
    • NET client object model
    • Silverlight client object model
    • Mobile client object model
  • JavaScript object model
  • Representational State Transfer (REST) service
  • Server object model

Link to Follow Content in SharePoint 2013, I can just find how to do it with REST or CSOM.

2

You have to use SPSocialFollowingManager to follow a user to document/site etc in Server Object model. Below is a code snippet how to do it.

                //Get the UserProfile for user
                SPServiceContext serverContext = SPServiceContext.GetContext(properties.Web.Site);
                UserProfileManager profileManager = new UserProfileManager(serverContext);
                UserProfile profile = profileManager.GetUserProfile(loginName);
                if (profile != null)
                {
                    //Social following manager object for the user's profile
                    SPSocialFollowingManager manager = new SPSocialFollowingManager(profile);

                    //Initialise  social actor with the newly created web 
                    SPSocialActorInfo actorInfo = new SPSocialActorInfo();
                    actorInfo.ContentUri = new Uri(url);//url=URL of the new sub site created
                    actorInfo.AccountName = targetUser.LoginName;
                    actorInfo.ActorType = SPSocialActorType.Site;

                    //Follow on this actor
                    manager.Follow(actorInfo);
                }

Also see this Blog Post which is similar to what you want to achieve.

  • This was just what i needed! Thanks, for the blog post link aswell! – George Norberg Apr 25 '14 at 7:10

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.