2
votes

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.

1

1 Answers

1
votes

Just wanted to Share, this Solved the task.

Just a Follow Method that takes a SPWeb object and a SPUser object.

SPServiceContext serverContext = SPServiceContext.GetContext(web.Site);
UserProfileManager profileManager = new UserProfileManager(serverContext);
string userString = user.LoginName.ToString();
UserProfile userProfile = profileManager.GetUserProfile(userString);

        if (userProfile != null)
        {
            SPSocialFollowingManager manager = new   
            SPSocialFollowingManager(userProfile);
            SPSocialActorInfo actorInfo = new SPSocialActorInfo();
            actorInfo.ContentUri = new Uri(web.Url);
            actorInfo.AccountName = user.LoginName;
            actorInfo.ActorType = SPSocialActorType.Site;
            manager.Follow(actorInfo);
        }