Azure / Office 365 / SharePoint Development / Search

Take your SharePoint social features to the next level with “I like it” and “Tags” counters: Part 2

April 04, 2012

In the previous part I talked about retrieving the number of tags by code. The problem was that the GetTags method from the SocialTagManager class, could only retrieve tags from a specific user.

In this part I show you a way to retrieve the all the tags for a specific location/page.


My first step was to check the SocialTagManager class to see the code of the GetTags methods. The SocialTagManager class can be found in the Microsoft.Office.Server.UserProfiles.dll.



The SocialTagManager class contains 13 GetTags methods, and only four of them are public.

GetTags Methods

GetTags Methods

The method that could retrieve all the tags (a maximum of 1000) is the following GetTags(Uri url, Int32 maximumItemsToReturn, SocialItemPrivacy socialItemPrivacy).

Internal GetTags Method

Internal GetTags Method

It seems that this method does not use the current user of a specific user to filter the tags. The only problem is that this is an internal method.

The solution is to use reflection, this will allow you to make use of the GetTags(Uri url, Int32 maximumItemsToReturn, SocialItemPrivacy socialItemPrivacy) method.


More information about reflection can be found here.

The first thing you need to do is retrieving all the nonpublic methods of your SocialTagManager class. This can be done as follows:

Now that you got all the nonpublic methods, you can retrieve the GetTags method. I used the following statement to do this:

The only thing that rests is to invoke the retrieved GetTags method. This can be done like this:

When you use these code snippets in the console application from part 1, you should now get other results for the items (if you have enough tags, and likes).

Reflection GetTags Method Result

Reflection GetTags Method Result

When you compare this result with the first part, you can see that "How To Use This Library" has 2 likes more than in the first part.

Social Tags

Social Tags

Complete Source Code

GetTags Code

Part 3

In the next part I will show you how you can put this in a usercontrol, so that these results can be displayed on all your pages.


  • Oliv

    Very useful, Great Works! Is your code working with a remote user profile SA ?

    • estruyf


      Didn’t test this. When you do, could you leave a comment with the result? Thanks!