none
Get the number of "I Like It" tags for an Item

    Question

  • Hi guys,

    I would like to get the count of how many times and item was signed "I like it".

    how can I do that?


    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Friday, January 21, 2011 9:34 AM

Answers

  • Ok I understand... the method: GetAllTagTermsForUrlFolder

    it's what I need tnx Dmitry


    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    • Marked as answer by Salvo Di Fazio Wednesday, January 26, 2011 10:31 AM
    Wednesday, January 26, 2011 10:31 AM
  • Hi Salvo,

    As I mentioned above you may use SocialDataService web service for your task. Please look at this console application. It works as you wish.


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using GetTagCount.HerculesWebReference;
    using System.Net;
    
    namespace GetTagCount
    {
      class Program
      {
        public static long GetCountTags(string URL, string tag)
        {
          SocialDataService SocialDataService = new SocialDataService();
          
          mySocialDataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
          List<SocialTermDetail> list = mySocialDataService.GetTagTermsOnUrl(URL, null).Where(t => t.Term.Name.Equals(tag)).ToList();
    
          return list.Count != 0 ? list[0].Count : 0;
        }
    
        static void Main(string[] args)
        {
          string pageURL = "http://hercules/Lists/Calendar/calendar.aspx";      
          string tag = "I like it";
    
          Console.WriteLine(GetCountTags(pageURL, tag).ToString() + " tags " + tag);
        }
      }
    }
    

    hercules - is name of my machine

    HerculesWebReference - is name of my added web reference to this project. URL of this web reference is "http://hercules/_vti_bin/socialdataservice.asmx "

    You should just replace "hercules" in the code and web reference with your server name.

     

    Dmitry

     


    Lightning Tools Check out our SharePoint tools and web parts

     


    • Marked as answer by Salvo Di Fazio Wednesday, January 26, 2011 10:31 AM
    Wednesday, January 26, 2011 12:05 AM

All replies

  • Hi Salvo,

    I think SocialDataService will help you. You may use SocialDataService.GetTags method for your needs.

     

    Dmitry

     


    Lightning Tools Check out our SharePoint tools and web parts

     


    Friday, January 21, 2011 12:45 PM
  •  public static List<SocialTag> GetILikeIts()
     {
    
          SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default,
            SPSiteSubscriptionIdentifier.Default);
    
          SocialTagManager stm = new SocialTagManager(context);
    
          SocialTag[] tags = stm.GetTags(new Uri("http://basesmc2008/tester/document.docx");
          
            
          if (tags != null)
            return tags.Where(t => t.Term.Name == "I like it" && t.Url.ToString().Contains("DispForm.aspx")).ToList();
          else
            return null;
    
          
          
    }
    

    Try:

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    • Proposed as answer by Marco RizziMVP Saturday, January 22, 2011 10:02 AM
    • Unproposed as answer by Salvo Di Fazio Tuesday, January 25, 2011 4:48 PM
    Friday, January 21, 2011 3:54 PM
  • Mmmm I would like to have the count of "I like it" for all the users on the application!
    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Tuesday, January 25, 2011 4:49 PM
  • Hmmm. I thought your original question was looking for a count of "I Like it"  for an item. Can you explain what you are looking for? The total number of "I Like it" for a particular web application?


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Tuesday, January 25, 2011 5:02 PM
  • I try to explain me better :)

    I need to get for an item of many times it was "I like it" tagged by every user.


    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Tuesday, January 25, 2011 5:06 PM
  • public static int GetCountLikeIts()
    {
          int count = 0;
    
          SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default,
            SPSiteSubscriptionIdentifier.Default);
    
          SocialTagManager stm = new SocialTagManager(context);
    
          SocialTag[] tags = stm.GetTags(new Uri("http://basesmc2008/tester/document.docx"));
    
          if (tags != null)
          {
            var results = tags.Where(t => t.Term.Name == "I like it");
            if (results != null)
              count = results.Count();
    
          }
    
          return count;
    }
    

    Ok, you can use linq also to return the count of "I Like it" for an item.

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Tuesday, January 25, 2011 5:17 PM
  • But the GetTags doesn't return the number of "I like it" for the current user?
    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Tuesday, January 25, 2011 5:21 PM
  •  public static int GetUserILikeIts()
     {
          
          int count = 0;
    
          SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default,
            SPSiteSubscriptionIdentifier.Default);
    
          UserProfileManager upm = new UserProfileManager(context, true);
          UserProfile up = upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
    
          SocialTagManager stm = new SocialTagManager(context);
    
    
          SocialTag[] tags = stm.GetTags(up);
    
          if (tags != null)
          {
            var results = tags.Where(t => t.Term.Name == "I like it");
            if (results != null)
              count = results.Count();
    
          }
    
          return count;
          
    }
    

    You need to get the current user's user profile:

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Tuesday, January 25, 2011 5:30 PM
  • yes Ok....

    My question is... the GetTags retrive the tag "I like it" for the item foreach user on the application or for the current user only?


    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Tuesday, January 25, 2011 5:32 PM
  • For the current user only. The GetTags method uses the HttpContext.Current.User property. So if you are trying to get another user's tags, then loading the other user's profile will not work. It can be done, but only with reflection.
    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Tuesday, January 25, 2011 5:38 PM
  • Ok so... it is not the answer for my problem.

    I need to get for an item of many times it was "I like it" tagged by every users in the application


    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Tuesday, January 25, 2011 5:39 PM
  • public static int GetCountLikeIts()
    {
          int count = 0;
    
          SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default,
            SPSiteSubscriptionIdentifier.Default);
    
          SocialTagManager stm = new SocialTagManager(context);
    
          SocialTerm[] terms = stm.GetTerms(new Uri("http://basesmc2008/Shared%20Documents/Forms/AllItems.aspx"));
    
          if (terms != null)
          {
            var results = terms.Where(t => t.Term.Name == "I like it");
            if (results != null)
              count = results.Count();
    
          }
    
          return count;
    }
    

    You must use the GetTerms method. However, the caller of the code must be set up as an Administrator with the "Manage Social Data" permission for the "User Profile Service Application"

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Tuesday, January 25, 2011 5:57 PM
  • Hi Salvo,

    As I mentioned above you may use SocialDataService web service for your task. Please look at this console application. It works as you wish.


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using GetTagCount.HerculesWebReference;
    using System.Net;
    
    namespace GetTagCount
    {
      class Program
      {
        public static long GetCountTags(string URL, string tag)
        {
          SocialDataService SocialDataService = new SocialDataService();
          
          mySocialDataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
          List<SocialTermDetail> list = mySocialDataService.GetTagTermsOnUrl(URL, null).Where(t => t.Term.Name.Equals(tag)).ToList();
    
          return list.Count != 0 ? list[0].Count : 0;
        }
    
        static void Main(string[] args)
        {
          string pageURL = "http://hercules/Lists/Calendar/calendar.aspx";      
          string tag = "I like it";
    
          Console.WriteLine(GetCountTags(pageURL, tag).ToString() + " tags " + tag);
        }
      }
    }
    

    hercules - is name of my machine

    HerculesWebReference - is name of my added web reference to this project. URL of this web reference is "http://hercules/_vti_bin/socialdataservice.asmx "

    You should just replace "hercules" in the code and web reference with your server name.

     

    Dmitry

     


    Lightning Tools Check out our SharePoint tools and web parts

     


    • Marked as answer by Salvo Di Fazio Wednesday, January 26, 2011 10:31 AM
    Wednesday, January 26, 2011 12:05 AM
  • Mmmm ok.. I don't find the object SocialDataService in my http://<servername>/_vti_bin/socialdataservice.asmx  .... :-\
    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Wednesday, January 26, 2011 8:53 AM
  • Hi Salvo,

    You may see here http://msdn.microsoft.com/en-us/library/ee590739.aspx Web service reference: http://Site /_vti_bin/SocialDataService.asmx

    Is this URL http://Site /_vti_bin/SocialDataService.asmx unavailable at your SharePoint server? Can't you see WSDL http://Site /_vti_bin/SocialDataService.asmx?wsdl of this web service?

     

    Dmitry

     


    Lightning Tools Check out our SharePoint tools and web parts

     


    • Marked as answer by Salvo Di Fazio Wednesday, January 26, 2011 9:23 AM
    • Unmarked as answer by Salvo Di Fazio Wednesday, January 26, 2011 9:23 AM
    Wednesday, January 26, 2011 9:21 AM
  • I understand the error... I had added it like a wcf :)
    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Wednesday, January 26, 2011 9:28 AM
  • Hi Salvo,

    Does my example work as you wish? You may use method

    public
     static
     long
     GetCountTags(string
     URL, string
     tag)

    for counting any other tag.

    Dmitry

     


    Lightning Tools Check out our SharePoint tools and web parts

     


    Wednesday, January 26, 2011 9:36 AM
  • Mmm I working on it...

    I have to count the "I like it" tag for a discussion board's item...

    It doesn't work... :-\

    ufffffffff


    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Wednesday, January 26, 2011 9:37 AM
  • What URL of your discussion board item?

     

    Dmitry

     


    Lightning Tools Check out our SharePoint tools and web parts

     


    Wednesday, January 26, 2011 9:40 AM
  • when I click in the thread the url is: http://win-t3grou4gkaj/Lists/ILikeItTest/Flat.aspx?RootFolder=%2FLists%2FILikeItTest%2Fddas&FolderCTID=0x012002000BA9A61DB5B69A4BB51C1FAAD2E618EE
    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Wednesday, January 26, 2011 9:49 AM
  • Maybe I need to waiting that the Social Data Server understand that the page or item was tagged?
    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    Wednesday, January 26, 2011 10:08 AM
  • Ok I understand... the method: GetAllTagTermsForUrlFolder

    it's what I need tnx Dmitry


    Salvatore Di Fazio Microsoft Certified Trainer Microsoft Certified Professional Developer http://bitvector.tostring.it https://www.mcpvirtualbusinesscard.com/VBCServer/salvatore.difazio/profile
    • Marked as answer by Salvo Di Fazio Wednesday, January 26, 2011 10:31 AM
    Wednesday, January 26, 2011 10:31 AM
  • Can you count tags on this page via SharePoint 2010 Central Administration->Application Management ->Manage service applications->User Profile Service Application->Manage Social Tags and Notes

    You should enter your URL and click Find

     

    Dmitry

     


    Lightning Tools Check out our SharePoint tools and web parts

     


    Wednesday, January 26, 2011 10:48 AM
  • hey ! is there any way to programatically get list of users who have tag an item " I Like it ".
    Thursday, March 24, 2011 5:51 PM
  • Is it possible to count Tags during a specific period. For example how many "I like tags" are createded during the last 30 days in my webbapplication.
    Tuesday, May 31, 2011 9:32 AM
  • Can we do this using the Object model and not the web service?
    Monday, June 11, 2012 3:13 PM