Another feature I’ve been looking at lately is letting users rate content posted to a SharePoint blog. I’ve seen it done before, but sometimes running custom code on the server isn’t an option, so I’ve been working on an implementation that doesn’t require anything special server side.
On the server, all I need to set up is a ratings list with two columns - PostID and Rating. Users will need contribute access to the list.
The first part of the implementation (after adding some test data to the ratings list) is to retrieve all the ratings for a specific post.
Making the request itself is reasonably easy :
xmlhttp.open("POST", "/_vti_bin/Lists.asmx",true); xmlhttp.setRequestHeader("Content-Type","text/xml; charset=utf-8"); xmlhttp.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetListItems"); xmlhttp.setRequestHeader("Content-Length", xmlrequest.length); xmlhttp.onreadystatechange=GetRatingsHandler; xmlhttp.send(xmlrequest);
The tricky part is getting the value of xmlrequest right - the documentation for the web service isn’t much help.
[xml lost in some long ago blog migration]
Adding a new rating is easy once you have GetListItems working. The documentation for Lists.UpdateListItems on MSDN is reasonably clear on actual usage.
This approach obviously isn’t going to scale to millions of ratings, but if you have a site getting that much usage you probably have sufficient access to do something better server side.