Social Tag can be created for any specified URL with a valid term using
SocialTagManager object. SocialTagManager object contains methods and properties
that are used to manipulate social tag data. Here we will be seeing how to get
all the social tags for the specified URL in SharePoint 2010 using the SharePoint
Object Model.
View all the social tags for the specified user through Central
Administration:
- Open Central Administration by going Start | All Programs | Microsoft
SharePoint 2010 Products | SharePoint 2010 Central Administration.
- Click on Manage Service Application which is available in Application
Management section.
Figure : Application Management section in SharePoint 2010
- Click on User Profile Service Application.
- Click on Manage Social Tags and Notes which is available in "My Site
Settings" section.
- Select Tags from the Type dropdown and enter the User.
- Click on Find.
- You could be able to see the Social Tags for the specified user.
Programmatically get all the social tags for the specified user:
Steps Involved:
- Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual
Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run
as administrator.
- Go to File tab, click on New and then click on Project.
- In the New Project dialog box, expand the Visual C# node, and then
select the Windows node.
- In the Templates pane, select Console Application.
- Enter the Name and then click OK.
- In the solution explorer, right click on the solution and then click on
Properties.
- Select the Application tab, check whether ".Net Framework 3.5" is
selected for Target Framework.
- Select the Build tab, check whether "Any CPU" is selected for Platform
Target.
- In the solution explorer, right click on the References folder and click
on Add Reference.
- Add the following references.
-
Microsoft.SharePoint.dll
-
Microsoft.Office.Server.UserProfiles.dll
-
Microsoft.Office.Server.dll
- Double click on Program.cs and add the following Namespaces.
-
using Microsoft.Office.Server.SocialData;
-
using Microsoft.SharePoint;
-
using Microsoft.Office.Server;
-
using Microsoft.Office.Server.UserProfiles;
- Replace Program.cs with the following code snippet.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using
Microsoft.Office.Server.SocialData;
using Microsoft.SharePoint;
using
Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server;
namespace
UserProfilesPOC
{
public
class Program
{
public
static void
Main(string[] args)
{
using (SPSite
site = new
SPSite("https://servername.com/finance/Finance/"))
{
//// Get the context of
the service application
SPServiceContext
context = SPServiceContext.GetContext(site);
////UserProfileManager is
used to create a UserProfile object and then
retrieve the corresponding data from the user profile database.
UserProfileManager userProfileManager =
new
UserProfileManager(context);
////Gets the UserProfile
object for the specified account name
UserProfile
userProfile = userProfileManager.GetUserProfil
(@"domainname\username");
//// SocialTagManager -
Contains methods and properties used to
manipulate social tag data
SocialTagManager
socialTagManager = new
SocialTagManager(context);
//// GetTags(userProfile)
method is used to retrieve an array of
SocialTag objects for the specified user.
SocialTag[]
tags = socialTagManager.GetTags(userProfile);
Console.WriteLine("Tags
for the User Profile: " +
userProfile.DisplayName);
foreach (SocialTag
tag in tags)
{
Console.WriteLine("###############################################";
Console.WriteLine("
Tag Name : " + tag.Term.Name);
Console.WriteLine("
URL : " + tag.Url.AbsoluteUri);
Console.WriteLine("
Title : " + tag.Title;
}
Console.ReadLine();
}
}
}
}
- In the solution explorer, right click on the solution and click on
Build.
- Hit F5.
Summary:
In this article you have seen how to get all the social tags for the
specified user in SharePoint 2010 using object model.