Tuesday, December 14, 2010

SharePoint 2010: Getting all site collection tags

For those trying to figure out how to get the list of all tags out of SharePoint 2010 here ya go:

//Add these using tags at the top of your class.
using Microsoft.Office.Server.SocialData;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint.Portal.WebControls;

//This is the code neccessary to pull out all tags for 
//the current site collection.
SPSite site = SPContext.Current.Site;
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager upm = new UserProfileManager(context);
UserProfile up = upm.GetUserProfile(false);
SocialTagManager stm = new SocialTagManager(context);
SocialTerm[] terms = stm.GetAllTerms();

No comments:

Post a Comment