Syrinx on SharePoint

Syrinx SharePoint Team Blog
Need help on your project? info@syrinx.com, or toll free (888) 579-7469, press 1

News



Need help with your SharePoint project?

Syrinx works with clients throughout New England and across the United States to architect, design, develop, and deploy SharePoint implementations. Working on fully outsourced projects, as part of your team, helping to train your team, or rescuing projects in trouble, we are comfortable doing it all. Projects from a couple weeks to several months in duration, reference clients available. Contact us today - info@syrinx.com, or toll free (888) 579-7469 and press 1 to speak to someone now!

Customized Content Rating for SharePoint

I wanted to share with you a recent client undertaking involving adding "star rating" and comments to SharePoint content.  As usual, clients prefer not to build everything from scratch, so I looked what was available via 3rd party options and found 2 potentially viable solutions:

SharePoint Document Rating System  from codeplex:  http://www.codeplex.com/spdocrating and a licensed offering from KwizCom:  http://www.kwizcom.com/

At the time, the codeplex solution seemed a little more difficult to deal with, requiring content types and multiple columns in a list to function.  These column also appeared to be based on non-standard formats, and it was not straightforward to use the columns as managed properties to create more fine-tuned search options.

Since the KwizCom solution was simply a custom field type installed into SharePoint based on a common decimal base type, it seemed much easier to implement.  The downside was that it was some custom code, not open source, and it was entirely obfuscated so when I needed to make some adjustments based on my requirements, I was really stuck with what they gave me.  Here's what I did in case someone is thinking about doing this:

I added their custom field to my SharePoint environment and created a site column from it called Ratings.  Below is a screen shot of what this looks like in a list/library

ratings1 ratings2

The above shows what the column looks like and what it shows you when you hover over the item.  When you click on the item you get a pop up where you can rate and read comments similar to this:

ratings3

ratings4

Ok, so the easy part is done:  Install the product and add it to a list, and fill out some data.  They give you that for free :)  Now I had to come up with my own solution for the next 2 problems.  First, I needed to include the ratings for documents in search results.  It turns out to be pretty easy, but there were a couple wrinkles.

1.  I had to copy some images over from the KwizCom installation location to where the layout images live in the 12 hive here:  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\IMAGES

2.  Then I had to modify the Search Results page (Search Core Results) to include my column in the XML, and then add a series of XSL "when" to display the star rating image AND the link to the comments as this was a requirement.

<xsl:when test="contentrating='1'"> - <img align="top" style="cursor:pointer;" onclick="window.ratingelement=this.parentNode;commonShowModalDialog('/_layouts/RatingRedirect.aspx?ItemURL={url}&amp;SiteName={sitename}&amp;a=1' ,'dialogHeight:450px;dialogWidth:350px;scroll:no;toolbar:no;status:no;resizable:no;', null, this.parentNode);" src="_layouts/KWizCom_RatingSolution/Images/1.0.gif"/></xsl:when>

The savvy of you may look at this XSL and wonder what "RatingRedirect.aspx" is.  Well, this is something I had to come up with because the KwizCom code is locked down.  Essentially I had to write a gateway page that took the querystring data available in the search results page and send it to a location that had the ability to look up the proper data required by the KwizCom page to load rating details.  The aspx page code I wrote looks like this:

public partial class RatingRedirect : System.Web.UI.Page
   
{
       
protected void Page_Load(object sender, EventArgs e)
       
{
           
ProcessRedirect();
       
}

       
private void ProcessRedirect()
       
{
           
string itemURL = Request.QueryString["ItemURL"];
           
string siteUrl = Request.QueryString["SiteName"];
           
string destination = Request.QueryString["a"];

           
using (SPSite mySite = new SPSite(siteUrl))
           
{
               
using (SPWeb myWeb = mySite.OpenWeb())
               
{
                   
SPListItem item = myWeb.GetListItem(itemURL);
                   
if (item != null)
                   
{
                       
if (destination == "1")
                       
{
                           
Response.Redirect(item.Web.Url + "/_layouts/KWizCom_RatingSolution/RatingPopup.aspx?itemId=" + item.ID + "&listId={" + item.ParentList.ID + "}");
                       
}
                       
else if (destination == "2")
                       
{
                           
Response.Redirect(item.Web.Url + "/_layouts/KWizCom_RatingSolution/CommentsPopup.aspx?itemId=" + item.ID + "&listId={" + item.ParentList.ID + "}");

                       
}
                   
}
                   
else
                   
{
                       
Response.Write("<br>   Sorry, this item cannot be rated.");
                   
}
               
}
           
}

       
}
   
}

The basics here are that I need to some ListItem data that is completely unavailable at the search results page.

Also consider that only list items can contain ratings.  Much of the unratable content can be exluded from search results using contentclass exclusions in your search scopes, but the one that tripped me up was a standard site aspx page.  If the page did not live in a library but was returned in search results, it would display with zero ratings.  When a user clicked on the details they would receive an error because this was an unratable item.  You see my rudimentary error handling section in the code above to at least inform people about the status.

We also added a higher level check in the XSL to only return rating data from content sources that actually had the rating installed.  Other SharePoint web applications or site collections within the SSP that does not contain rating data needs to be excluded.

These changes allowed my search results to show the ratings details AND allowed users to view the comments AND add their own comments right from the search results page.  The only hiccup is that until another crawl is run, the changes won't be shown in the search results because that data is pulled from the index and not in real time.  A small price to pay.

ratings5

Finally, I had to deploy this.  Essentially the client wanted to add this to any document libraries that already existed in their site collection.  It seems every client requires me to write a tool that iterates over a site collection and checks for something in each web/list.  It's either inheritance, permissions, features, etc. that need to be set for every list if some condition is met.  So I had some code I could re-use.  I won't paste the whole thing here, but it was pretty simple:

I iterated over every site and did the following:  checked for each list to see if it inherited from base templates of document library or link lists.  If so, I iterated over the fields to see if the Rating field was present.  If not, I would add the field to the list, then add it to the default view of the list. 

Then you have to "tickle" the list, and un-tickle it.  This one was critical.  Due to the nature in which this data is stored, there is an inherent bug with the KwizCom solution.  Their design created a hidden list per web that holds the rating data.  This list is not created until a least one rating is made in the web.  This code must not run with elevated permissions because users without proper permissions to create the list will receive an error.  It's odd that they missed this because their solution only requires read access in order to rate items, so they must have written elevated permission code elsewhere in their solution.

At any rate, the tickle adds a rating to the first item in the list, updates the item, then removes the rating.  This ensures the container list exists moving forward.

All in all it did not take too long to implement and the 3rd party price was pretty inexpensive.

I hope this helps,

-Ryan Thomas

Comments

Futile » links for 2009-07-24 said:

Pingback from  Futile &raquo; links for 2009-07-24

# July 24, 2009 1:30 PM

For Sale By Owner Daytona, Rolex Daytona Sale said:

Pingback from  For Sale By Owner Daytona, Rolex Daytona Sale

# May 21, 2010 2:36 PM

Volare Discount Auto Parts Front Suspension, Volare Clearance Rear Derailleur Measure Your Inseam said:

Pingback from  Volare Discount Auto Parts Front Suspension, Volare Clearance Rear Derailleur Measure Your Inseam

# May 21, 2010 7:10 PM

Sidekick 2009 Unboxing, Call Custom Ringtones Sidekick Slide said:

Pingback from  Sidekick 2009 Unboxing, Call Custom Ringtones Sidekick Slide

# May 21, 2010 8:05 PM

1993 Reliability 1995 Mazda Rx 7, 2003 Sale 2002 Mazda Protege5 said:

Pingback from  1993 Reliability 1995 Mazda Rx 7, 2003 Sale 2002 Mazda Protege5

# May 22, 2010 1:14 PM

Toyota Avalon Door Latch, Toyota Avalon Replacement Save said:

Pingback from  Toyota Avalon Door Latch, Toyota Avalon Replacement Save

# May 22, 2010 2:10 PM

Ls400 Full Rear Wheel Drive, 2001 Volvo S40 Check Engine - 29.an74.com said:

Pingback from  Ls400 Full Rear Wheel Drive, 2001 Volvo S40 Check Engine - 29.an74.com

# May 23, 2010 8:23 AM

Acer Aspire One Aod 150 1893, Ford Aspire Kia Avella Sold - 165.unlockiphone30.net said:

Pingback from  Acer Aspire One Aod 150 1893, Ford Aspire Kia Avella Sold - 165.unlockiphone30.net

# May 25, 2010 8:34 PM

1996 - 1983 @ Toyota Cressida Cars Sale Mr2 Spyder, Toyota Cressida Radio Installation - 38.tijuanareader.com said:

Pingback from  1996 - 1983 @ Toyota Cressida Cars Sale Mr2 Spyder, Toyota Cressida Radio Installation - 38.tijuanareader.com

# May 31, 2010 1:43 AM

1989 - 1988 @ Parts Infiniti Qx56 Performance Chip, G20 Free Shipping Qx4 Parts Infiniti Qx56 - 279.jordanbrandallamerican.com said:

Pingback from  1989 - 1988 @ Parts Infiniti Qx56 Performance Chip, G20 Free Shipping Qx4 Parts Infiniti Qx56 - 279.jordanbrandallamerican.com

# May 31, 2010 2:52 AM

1988 - 2009 @ Continental Contiprocontact Ssr Ebay, Radiator Market Chevy Ssr - 154.defutbolazo.com said:

Pingback from  1988 - 2009 @ Continental Contiprocontact Ssr Ebay, Radiator Market Chevy Ssr - 154.defutbolazo.com

# May 31, 2010 2:18 PM

horoscopes said:

Pingback from  horoscopes

# December 23, 2011 8:58 PM

horoscopes said:

Pingback from  horoscopes

# December 23, 2011 8:58 PM