If you find this article useful, please consider a donation.
Applies to:
- Microsoft Office SharePoint Portal Server
- Microsoft SharePoint Designer 2007
Summary:
Using SharePoint Designer 2007, customize a Microsoft Windows SharePoint Blog site to allow users to vote on and rank Blog posts.
You may download a 60-day trial of Microsoft SharePoint Designer 2007 at
Microsoft’s website – http://office.microsoft.com/en-us/sharepointdesigner.
Set up your SharePoint Blog and Survey List
1. Create a new Blog site within your SharePoint site.
2. Click View All Site Content from the Quick Launch Menu

3. Click Create from the Menu bar

4. Click Survey from the Tracking list

5. Create a new Survey with the following settings:
a. Name: Ranking
b. Display Survey on the Quick Launch? No
c. Show user names in survey results? Yes
d. Allow multiple responses? Yes
6. Click Next

7. Create a new question in the survey with the following settings:
a. Question: Post
b. The Type of answer to this question is: Single line of text
c. Require a response to this question? Yes
d. Maximum number of characters: 255 (default)
8. Click Next Question

9. Create a new question in the survey with the following settings:
a. Question: Ranking
b. The Type of answer to this question is: Choice (menu to choose from)
c. Require a response to this question? Yes
d. Type each choice on a separate line: 1 2 3 4 5
e. Display choices using: Radio Buttons
f. Allow ‘Fill-in’ choices: No
10. Click Finish

Add a survey response
11. Click Respond to this Survey
12. Type Welcome to your Blog! (the default Blog post title).
13. Select a Rank from the list.
14. Click Finish.


Calculate the Blog post’s Average Rank
1. Open the site using SharePoint Designer 2007.
2. Right Click the default.aspx page and Select Check Out.
3. Right Click the Blog entry ListViewWebPart and Select Convert to XSLT Data View.


Once converted, you will be able to edit the ListViewWebPart.
4. Click the white space after the Blog post’s date/time field and add a vertical
bar – |.

Create a Linked Data source
5. Select Data Source Library from the Task Panes menu
6. Select Create a new Linked Source from the Linked Sources section of the Data Source Library list.


7. Click Configure Linked Source…
8. Highlight Posts and Ranking from the Available Data Sources list on the Left.
9. Click Add >>

10. Click Next to continue
11. Select Join the contents of the data sources by using the Data Source Details to insert data views and joined subviews.
12. Click Finish

13. Click the General tab and type Post Ranks as the Name.
14. Click OK

15. Select Data Source Details from the Task Panes menu.

16. Select Link to another data source… from the Related Data Sources dropdown menu.

17. Click OK

18. Select Posts and Post Ranks from the Available Data Sources list.
19. Click Add
20. Click Next and Finish


Insert the Blog Post’s Rank
21. Place the cursor to the right of the vertical bar near the Blog Post’s date and time.
22. Select the Ranking Row from the Ranking Data Source.
23. While Ranking is selected, Click Insert Selected Fields as… > Item(s).

24. Highlight the newly inserted ranking Item.
25. Right Click on the Item and Select Edit Formula.


26. Replace the XPath expression:
../../../Post_Ranks/Ranking/Rows/Row/@Ranking
with
(sum(../../../Post_Ranks/Ranking/Rows/Row[@Post=current()/@Title]/@Ranking) div
count(../../../Post_Ranks/Ranking/Rows/Row[@Post=current()/@Title]/@Ranking))


27. Right Click on the Item again, point to Format Item as, and Select Number…
28. Add one decimal place to the Format Number Option.


29. Add “Ranked” before the Item Ranking and “out of 5.” after the Item Ranking.
The full sentence should read, “Ranked x.x out of 5.”
30. Save your work and press F12 to preview the page.

Click Yes if you receive a Site Definition Page Warning message.

Use Parameters to Connect a Vote Now link to the Ranking Survey
1. In the Folder List, Right Click on NewForm.aspx within the Ranking folder and Select Check Out.
2. Open the NewForm.aspx document to Edit it.


3. Right Click on the Ranking Web Part and select Web Part Properties.
4. Check the Hidden box under Layout.


5. Right Click under the Hidden Ranking Web Part, Point to Insert, and Select Row Below.
6. Place the cursor in the newly inserted row.

7. On the Insert menu, point to SharePoint Controls, and then click Custom List Form…

8. Select Ranking as the List, Ranking as the Content type, and New item form as the Type of form to create..
9. Click OK.

10. Right Click the Post field, Point to Format Item as, and click Text Box

11. Highlight the Post text box, then set the ReadOnly attribute in the Tag Properties window to True.

12. Click the small icon near the top Cancel button, select Common Data View Tasks, and then select Parameters…

13. Create a New Parameter with the following settings:
a. Name: Post
b. Parameter Source: Query String
c. Query String Variable: Post
14. Click OK.

15. Highlight the Post text box. In the Code view, change text=”{@Post}” to
text=”{$Post}” . The @ should be change to a $.
Save your work. Click Yes if you receive a Site Definition Page Warning message.

16. Type Vote Now! after the Ranked x.x out of 5. text.
17. Select Vote Now!
18. On the Insert menu, select Hyperlink.
19. In the Address field, type – Lists/Ranking/NewForm.aspx?Post={@Title}
20. Click OK.
21. Click Save and press F12 to preview the page.


Click Vote Now!
The Blog Post Title is automatically passed as a parameter to the Post field.


22. Create a new Blog Post.

Since there are no votes for the new Post, no Rank is displayed.

Use Conditional Formatting to Rank Posts with No Votes
1. Type a zero (0) after the current Rank.
⇒ Ranked 5.00 out of 5.

2. On the Task Panes menu, select Conditional Formatting.

3. With the zero (0) highlighted, click Create on the Conditional Formatting Task Pane, and then select Show content…
4. Click Advanced… to enter an Advanced Condition.

The Advanced Condition will show a zero (0) whenever the Rank Count is equal to zero.
(count(../../../Post_Ranks/Ranking/Rows/Row[@Post=current()/@Title]/@Ranking))=0
5. Enter the above XPath expression and click OK.
6. Click OK again.


The zero (0) should disappear from the design view.
Save your work and press F12 to preview the page. The zero (0) is now displayed on
your new Post – Ranked 0 out of 5.















I am unable to recreat your Blog Rating System. Not sure if there is a step or screen print missing because my Data Source Details list does not show Post_Ranks as an expanding folder. My screen shows Posts and Ranking in seperate folders with Post_Ranks under agg:source in each. Do you have any ideas why there is a difference?
I did miss a step/screen print. I think you may be selecting “Merge the contents of the data sources.” Instead, select “Join the contents of the data sources.”
I updated the post to reflect the missing screen print. You may view it here.
Good catch! Thanks!
Hi Jason,
I am trying to get the averaging of the poll numbers and I can’t get the code you have in step 26 to work. When I change the xPath Expression to what you have I get an error “The Current xPath expression may be invalid. Click OK to continue, or click Cancel to edit your changes.” When I click OK, the number changes from “5.0″ to “NaN”.
Any ideas as to why the code isn’t working for me? I have followed all the rest of the steps and haven’t hit any other problems.
“NaN” means Not A Number. Something is causing the xPath Expression to error out.
Double check all of the names (e.g. the survey, linked data source, etc.) to ensure they are accurate. They should match the names in the post.
Also, when you edit the formula for the ranking item (Step 25), does the xPath expression match the following:
If it’s different, you may have to update the formula that calculates the average.
Hope this helps!
Hi Jason,
I double checked all the names and made sure the xPath expression that is being replaced matches the one you have above. I am still getting “NaN” when trying to change the formula. Any other suggestions?
Aaron -
Is there someplace you can change the character into number? Maybe something before inputting the formula.
I am having the exact same problem as Aaron above, that code is not working for me and I have followed all the steps to a T. I also tried formatting the item as a number before changing the code to see if that would work but it didn’t. Suggestions? Is this a problem when the survey itself or the data links or what?
Thanks for this article, it’s very useful. I was able to get it all to work perfectly… for me. Unfortunately the “Ranked x.x out of 5. Vote Now” text/link only shows up for me though, not for any other users on the site… any ideas how to fix this problem?
To you guys talking about the NaN – when you first put in the formula it will show that for any posts without a ranking. Don’t worry about it and finish the rest of the instructions.
Nevermind, I just needed to check the page back in so other people could see the changes as well.
One thing I noticed is that you are able to rate a given blog article as many times as you want. Is there a way to limit each person to one vote per blog article? Maybe check if they’ve already voted on the article and if they have, let them modify their previous vote?
hi,
About the NaN, I solved it with these:
0
I hope that help!
bye
Sorry.. I added these before of ranking item’s code:
0
I hope it helps
Thank you, is there any way to make the voting section available for anonymous users?
Thank you very much Jason for your share. I will have a try.
SWEET! I’ve been looking everywhere for this. Can’t wait to try it tomorrow.
I can’t believe how nicely this worked. A+ for you man! I really appreciate the time and effort you put into this.
I love this soluition and plan to show it to my users. Thanks for posting it!
One thing I would like to change- when a user clicks “Vote now” and enters their ranking, after clicking OK they are returned to the summary page of the Ranking Survey.
I want them to be returned to the blog home page (the page listing all the posts). How can this be accomplished?
Also- one other thing that a previous poster asked about- is there a way to ensure that a user may only rank a post once?
Thank you! I’m glad you like it.
By default, Sharepoint returns users to the “All Items” view.
Add your blog home page URL to the end of the “Vote Now” link: ?Source=http:///default.aspx
Once the user votes, the survey form will read the “source=” section of the URL and navigate the user back to the blog home page.
Thanks- I actually remember how to do this after I posted that comment.
Can we ensure only one vote per user per post?
Spectacular job and it worked perfect. I would like to perform a similar task and was wondering if you might be able to help. I simply want a “vote” feature. So when you click “Vote now” you have the option of “yes” or “no”. Rather than displaying “Ranked x.x out of 5″; I would like to display “x(number) said yes, y(number) said no”. Where x= the total count on that post of users that selected “yes” and y=total count on that post of users that selected “no”.
Any help would be greatly appreciated, and again good job on this, it has already helped tremendously.
Hey Helen or anyone else who solved the NaN problem, how did you do it? what do you mean you put the 0 before the code? like 0(sum(../../../../Post_Ranks/Ranking/Rows/Row[@Post=current()/@Title]/@Ranking)div count(../../../Post_Ranks/Ranking/Rows/Row[@Post=current()/@Title]/@Ranking))
or like 0 before step 25 or what? Any help I would welcome. thx
Tyus and Other having NaN problem,
-go Step#25 and have Edit formula dialog box.
-Select your Data and cut it (for example you will be having like ../../../Thread_Rates/Ratings/Rows/Row/@Rating. cut it…)
-now you have nothing in xPath formula text box
-Double click on “Average” item under “Select a function to insert”
-it will insert “sum() div count()”
-paste your data under brackets of sum and count which you cut in previous step
-click on Ok
you are all set…
Jason Hi!
I’m not what you may call a SharePoint true expert. Actually i’m exploring SharePoint for the first time, but unfortunately (regarding your opinion) im starting with MOSS 2010. I’m trying to follow the steps for the ranking system in SP Designer 2010 but i’m finding it really difficult ’cause the interface is fundamentally different. Is there a way to replicate this mechanism on the 2010 beta environment?
Unfortunately, I have no experience with MOSS 2010 nor SP Designer 2010. If I get time, I’ll download a demo to test it out and post the results here.
Sorry I can’t be more help!
ranked
0.0
out of 5.0
sorry, i added some code above that got stripped,
but what I was trying to say is that i would add a test variable to the whole thing.
Like:
xsl:variable name=”postid” select=”current()/@ID
ranked
xsl:if test=”/dsQueryResponse/Ranking/Rows/Row[@PostID= $postid ]/@Ranking”
xsl:value-of select=”format-number(sum(/dsQueryResponse/Ranking/Rows/Row[@PostID= $postid ]/@Ranking) div count(/dsQueryResponse/Ranking/Rows/Row[@PostID= $postid ]/@Ranking), "###0.0;-###0.0")” /
xsl:if
xsl:if test=”not(/dsQueryResponse/Ranking/Rows/Row[@PostID= $postid ]/@Ranking)”
0.0
/xsl:if
out of 5.0
Hi Jason,
This voting does not work in categories part. it only works with default part.
Any Suggestion?