The Social Data Statistics Web Part displays social data statistics. This sample is a Microsoft Visual Studio 2010 SharePoint Visual Web Part project. After you build and deploy this project on your Microsoft SharePoint Server 2010 site, you can add this Web Part to any page where you want to display statistics for the social tagging activities of your users. The Web Part displays the following information, in three tables:
- Each URL that has been tagged, and the terms with which each URL has been tagged
- Each term that has been used in a social tag, and the number of times that term has been used
- Each user who has added a social tag, and the number of times that user has tagged URLs
//Change this value to the root URL for your site. string socialDataStatsSite = "http://mysite"; using (SPSite siteColl = new SPSite(socialDataStatsSite)) { //Create SocialTagManager with desired SPServiceContext. SPServiceContext serviceContext = SPServiceContext.GetContext(siteColl); UserProfileManager myUserProfileManager = new UserProfileManager(serviceContext); SocialTagManager mySocialTagManager = new SocialTagManager(serviceContext);
//Get all social terms and store in an array.
SocialTerm[] socTerms = mySocialTagManager.GetAllTerms();
//Create a Dictionary to store values for tags on social URLs, number of times each social term is used, //and number of times that each user has tagged a URL. Dictionary<string, string> SocialUrlStats = new Dictionary<string, string>(); Dictionary<string, long> SocialTermStats = new Dictionary<string, long>(); Dictionary<string, int> SocialTagStats = new Dictionary<string, int>();
//Get a Taxonomy term for each SocialTerm, get the number of times each social term has been used in a tag, //and get all the URLs for which that term has been used as a tag. Then map each URL to each of the terms with which //it has been tagged. foreach (SocialTerm aTerm in socTerms) { string termName = aTerm.Term.Name; SocialTermStats.Add(termName, aTerm.Count); try { SocialUrl[] socURLs = mySocialTagManager.GetAllUrls(aTerm.Term); foreach (SocialUrl aUrl in socURLs) { string urlString = aUrl.Url.ToString(); if (!SocialUrlStats.ContainsKey(urlString)) { SocialUrlStats.Add(urlString, termName); } else { SocialUrlStats[urlString] += ", " + termName; } } } catch (UserNotFoundException unfE) { // If the user is not found, handle exception. } }
//Get all the social tags in which the terms have been used. List<SocialTag> socialTagsList = new List<SocialTag>(); foreach (UserProfile userProf in myUserProfileManager) { try { SocialTag[] userTags = mySocialTagManager.GetTags(userProf, 0); foreach (SocialTag aTag in userTags) { socialTagsList.Add(aTag); } } catch (UserNotFoundException unfE ) { //If the user is not found, handle exception. } } //For each SocialTag, get the owner and get the number of times that owner has tagged a URL. foreach (SocialTag aTag in socialTagsList) { if (aTag != null) { if (!SocialTagStats.ContainsKey(aTag.Owner.DisplayName)) { int tagCount = mySocialTagManager.GetCount(aTag.Owner); SocialTagStats.Add(aTag.Owner.DisplayName, tagCount); } } }
//Bind each Dictionary to a GridView control. Display localized header strings for each column.
GridView1.DataSource = SocialUrlStats;
GridView1.Columns[0].HeaderText = Properties.Resources.String1;
GridView1.Columns[1].HeaderText = Properties.Resources.String2;
GridView1.DataBind();
GridView2.DataSource = SocialTermStats;
GridView2.Columns[0].HeaderText = Properties.Resources.String3;
GridView2.Columns[1].HeaderText = Properties.Resources.String4;
GridView2.DataBind();
GridView3.DataSource = SocialTagStats;
GridView3.Columns[0].HeaderText = Properties.Resources.String5;
GridView3.Columns[1].HeaderText = Properties.Resources.String2;
GridView3.DataBind();
}
Gots a question.
ReplyDeleteI'm trying to reference the social data namespaces in an application page; getting no love.
Have you run across this before; if so, is it simply "unavailable" in an application page or is it something I need to add to the GAC or something else?
Any insight appreciated.
Thank you for your time.
If your page generates an error indicating that it cannot find the control for this Web Part, navigate to \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES, and then rename SocialDataStatisticsWebPart to be VisualWebPartProject1.
ReplyDeleteLet me know if it solved ur problem.....
ReplyDelete