We recently made some changes to our SharePoint 2010 website that included renaming several sites, including the site url. It seems that this caused us to lose the ratings that were associated with our pages.

It appears the rating lives somewhere though because our search filter using the rating refiner still recognizes that the pages have ratings. However, if you click on the page from the search results after filtering on a rating selection, the rating control shows 0 ratings when you get to the page.

The search index had been deleted after the migration and you can save new ratings on our pages.

We're wondering if anyone had any ideas on what might've happened with the old ratings? We assumed they were part of the meta data of the page and shouldn't have been affected by the site name/url change. Are they tied to the URL somehow?

  • Looks like the ratings are tied to the absolute URL of the page and if the URL is changed the ratings are lost. There is a PowerShell script to move comments, but nothing for ratings that we can find. sadomovalex.blogspot.com/2011/07/…
    – sween_sp
    Mar 3 '14 at 21:16

Since Social Ratings Url is tied to Absolute Url, its value should be changed when the site name has been changed.

Below is demonstrated how to perform the renaming of Rating Url (the specified code could be executed in a console app):

    /// <summary>
    /// Migrate Ratings 
    /// </summary>
    /// <param name="siteUrl">Site collection url</param>
    /// <param name="sourceUrl">Rating source Url</param>
    /// <param name="targetUrl">Rating target Url</param>
    public static void MigrateRatings(string siteUrl,string sourceUrl,string targetUrl)
        using (var site = new SPSite(siteUrl))
            var context = SPServiceContext.GetContext(site);
            var upm = new UserProfileManager(context);
            var srm = new SocialRatingManager(context);
            foreach (UserProfile userProfile in upm)
                var ratings = srm.GetRatings(userProfile);
                foreach (SocialRating rating in ratings)

                    var migratedRatingUrl = rating.Url.AbsoluteUri.Replace(sourceUrl,targetUrl);
                    srm.DeleteRating(rating.Url); //delete original Rating
                    srm.SetRating(new Uri(migratedRatingUrl), rating.Rating);

                    Console.WriteLine(rating.Url + ": " + rating.Rating);




How to: Create and Retrieve a Social Rating

  • 1
    Thanks for this answer! We had come to the same conclusion. In our case, we will add a check to our Comments and Ratings webpart to see if ratings exist for the old URL and then update with the new url.
    – sween_sp
    Mar 4 '14 at 19:03
  • I'm glad it helped. Mar 4 '14 at 20:00

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.