So I have enabled Ratings in Sharepoint 2010 for a Document Library following this guide: http://weblogs.asp.net/开发者_开发技巧bsimser/archive/2009/10/19/sharepoint-2010-what-s-new-ratings-spc09.aspx
Now I need a way to get the ratings programatically in a Webpart.
I would like a way to get a list like the following (any other way is welcome though):
Item Id/Url | Rating | UserId
Thank you
I've found the answer here: http://msdn.microsoft.com/en-us/library/ff407954.aspx
It's funny I couldn't find it anywhere using Google, I should have search for "Sharepoint Social Rating" instead of just "rating".
You can you SPService to Get Rating on Url:
//Get Rating on Url
//libraryUrl is url of your library
$().SPServices({
operation: "GetRatingOnUrl",
url: libraryUrl,
async: false,
completefunc: function (xData, Status) {
if (Status == "success") {
var url = $(xData.responseXML).find("Url").text();
var rating = $(xData.responseXML).find("Rating").text();
var user = $(xData.responseXML).find("Owner").text();
....
}
}
});
When webservice return xml and then you can get some information you need like: Url, Owner, LastModifiedTime, Title and Rating
The following is a method for getting items from a list, and displaying them in a webpart. It uses a simple Label control, but you can format it any way you like:
Dim SPListVar As SPList 'SharePoint List
Dim SPColl As SPListItemCollection 'Define a list item Collection
Using Site1 As New SPSite(Me.Context.Request.Url.ToString) 'Define the site
Using Web1 As SPWeb = Site1.OpenWeb 'Define the web
SPListVar = Web1.Lists("Tasks") 'Point to the required list
End Using
End Using
SPColl = SPListVar.GetItems() ' Fill the List item collection with the return data
Dim i As Integer
While i < SPColl.Count
LblRes.Text = LblRes.Text + SPColl.Item(i).Item("Title").ToString + "<BR>"
'Read every record and put it in a new line in the Label control
i = i + 1
End While
精彩评论