How to get Count and List of documents and sites followed by a User in Office 365 SharePoint 2013 Site using CSOM

In this post, we will see how to retrieve list of followers for a document in Office 365 SharePoint site using .NET Client Object Model (CSOM).

Create a Console application and name it as ‘GetFollowers’

Add a reference to the following assemblies to the Console application.


Add a new C# class and name it as GetFollower.cs

Copy and paste the following code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using Microsoft.SharePoint.Client.Social;
using System.Security;

namespace GetFollowers
    public class GetFollowers

        public void RetrieveFollowedCount()
            using (var oClientContext = new ClientContext(“”))

                string UserName = “”;
                string Password = “password”;

                SecureString oSecureString = GetSecureString(Password);

                oClientContext.Credentials = new SharePointOnlineCredentials(UserName, oSecureString);

                //Instantiate SocialFollowingManager instance
                SocialFollowingManager oSocialFollowingManager = new SocialFollowingManager(oClientContext);

                //Instantiate SocialActorInfo class
                //SocialActorInfo oSocialActorInfo = new SocialActorInfo();
                //oSocialActorInfo.ContentUri = sDocUrl;
                //oSocialActorInfo.ActorType = SocialActorType.Document;

                //Invoke this private method to get the count of followed documents and sites
                GetFollowedCount(oClientContext, oSocialFollowingManager);

                //Invoke this private method to get actual list of documents and sites (objects)
                GetFollowedDocuments(oClientContext, oSocialFollowingManager);




        private static void GetFollowedCount(ClientContext oClientContext, SocialFollowingManager oSocialFollowingManager)
            //Set the SocialActorType as documents to get count of documents followed by user
            ClientResult<int> oFollowedDocsCount = oSocialFollowingManager.GetFollowedCount(SocialActorTypes.Documents);
            Console.WriteLine(“n”+”Total number of documents followed   :” + oFollowedDocsCount.Value.ToString());

            //Set the SocialActorType as documents to get count of sites followed by user
            ClientResult<int> oFollowedSiteCount = oSocialFollowingManager.GetFollowedCount(SocialActorTypes.Sites);
            Console.WriteLine(“n”+”Total number of sites followed    :” + oFollowedSiteCount.Value.ToString());

            //Set the SocialActorType as documents to get count of user followed by user
            ClientResult<int> oFollowedUserCount = oSocialFollowingManager.GetFollowedCount(SocialActorTypes.Users);
            Console.WriteLine(“n”+”Total number of users followed    :” + oFollowedUserCount.Value.ToString());

        private static void GetFollowedDocuments(ClientContext oClientContext, SocialFollowingManager oSocialFollowingManager)

            ClientResult<SocialActor[]> oSocialActors = oSocialFollowingManager.GetFollowed(SocialActorTypes.Documents);

            foreach (SocialActor oSocialActor in oSocialActors.Value)
                Console.WriteLine(“n”+”Name of followed document    :”+oSocialActor.Name);
                Console.WriteLine(“n”+”Document uri    :”+oSocialActor.ContentUri);
                Console.WriteLine(“n”+”Status    :”+oSocialActor.Status);


        //this method formats the input string into array of characters and place into SecureString object
        private static SecureString GetSecureString(String Password)
           SecureString oSecurePassword = new SecureString();

           foreach (Char c in Password.ToCharArray())

           return oSecurePassword;



The whole idea is that we are leveraging GetFollowedCount  method of SocialFollowingManager class to get count of documents and sites and we are leveraging GetFollowed method of SocialManager class to actually find out the documents (in the above).

Invoke this class from Program.cs

static void Main(string[] args)

           GetFollowers oGetFollowers = new GetFollowers();



Run the application and we will see the results below.


 Subscribe to my blog

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.