2

Just a quick question, is there any chance, how to get list of users, which rates items in one list, or documents in one library ? Maybe I only overlook something really obvious...

Thank you

1

SocialRatingManager.GetRatings can give you all Ratings for an Url or for a User.
See MSDN article How to: Create and Retrieve a Social Rating for more info for more info on how to work with ratings programatically

To get all ratings for a single library you can use code like this:

using System;
using Microsoft.Office.Server.SocialData;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace SharePointConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var url = "http://sp2010/TestDocs";
            using (var site = new SPSite(url))
            {
                var sc = SPServiceContext.GetContext(site);
                var sm = new SocialRatingManager(sc);
                using (var web = site.OpenWeb())
                {
                    var list = web.GetList(url);
                    foreach (SPListItem item in list.Items)
                    {
                        foreach (var rating in sm.GetRatings(new Uri(SPUrlUtility.CombineUrl(site.MakeFullUrl(web.ServerRelativeUrl), item.Url))))
                        {
                            Console.WriteLine("{0} rated {1} to {2}", rating.Owner.DisplayName, rating.Url, rating.Rating);
                        }
                    }
                }
            }
        }
    }
}
1
0

You can write a powershell with foreach for a site collection or a web and get a output text file.

# get the site collection
$s = get-spsite http://siteurl 

# loop through all site in the site collection, 
# then through all lists / libraries in that site (filtering out everything but actual doc libs 
# (The catalog filter excludes all sharepoint libs like the masterpage catalog etc.
// for each list, add a folder called test to the rootfolder
$s.AllWebs | Foreach-Object { 
  $_.Lists | Where { ($_.BaseType -eq "DocumentLibrary") -and ($_.BaseTemplate -notmatch "Catalog") } | Foreach-Object {
    # Do your code here and if u need to include basetype do so
    # 
  }
}
2
  • Thank you very much Ken! Can you write me the BaseType and Template for lists please? I'm not able to get list of users for list objects.
    – Molik
    Jul 2 '12 at 11:19
  • Sorry, but I don't see code to retrieve information about ratings in your PS script.
    – Raf
    Feb 14 '20 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.