Follow or UnFollow Sharepoint Web through CSOM (Programatically)

In Sharepoint 2013/2016 & Sharepoint online there are very nice features for social activities.

One of them is to follow or not follow webs. This can achieve by navigating to Delve page

But consider if we need to do this through APP or Console like from backend then

Here are two functions to Follow or Unfollow any web programmatically.

 

You need to copy this functions in your c# class file and they are ready to use.

Parameters are self-explanatory, first is clientContext object and other is url of the web.

 

public void StartFollowing(ClientContext clientContext, string url)

{

    SocialFollowingManager followingManager = new SocialFollowingManager(clientContext);

    clientContext.ExecuteQuery();

 

    SocialActorInfo actorInfo = new SocialActorInfo();

    actorInfo.ContentUri = url;

    actorInfo.ActorType = SocialActorType.Site;

 

    followingManager.Follow(actorInfo);

    clientContext.ExecuteQuery();

}

 

public void StopFollowing(ClientContext clientContext, string url)

{

    SocialFollowingManager followingManager = new SocialFollowingManager(clientContext);

    clientContext.ExecuteQuery();

 

    SocialActorInfo actorInfo = new SocialActorInfo();

    actorInfo.ContentUri = url;

    actorInfo.ActorType = SocialActorType.Site;

 

    followingManager.StopFollowing(actorInfo);

    clientContext.ExecuteQuery();

}

 

Cheers !

Search This Blog

Link Within Related Posts Plugin for WordPress, Blogger...