I had a requirement, which will allow SharePoint user's to vote for polls which are published by the SharePoint Administrator. You may think that we can use SharePoint Surveys which is already available in SharePoint 2010 as well as SharePoint 2007. But my thought of Surveys is, there are some limitations in Surveys and not to mention it has nice capabilities too.
If I talk about limitations, for an example I will mention one. Let's say that we want to create a Survey, which a user can vote once. And Survey has a nice optional inbuilt feature to block user from voting more than once. But again to one survey, we can add questions later. So let's take this scenario. Administrator adds a survey which has one question. He blocks user from voting twice. Someone votes and when he try to vote for the second time, SharePoint will not allow it. Then Administrator wants to add a another question to the created Survey. Then the problem arises. User can't answer to that question, because he is blocked from accessing the same Survey twice. So what will happen is, Administrator will have to take all the trouble of creating and configuring another Survey.
Since I did not want to get all the trouble, what I did was created a simple web part that will give the following functionalities.
- Easy to add a new Poll with one question.
- Can set a expiry date to the Poll and after it expires, users can't no longer see it or vote it.
- Each user can't vote more than once.
- Only the Administrator can view the results.
- Results can be viewed as Bar Charts or Pie Charts.
Now I am going to explain how I created it. Concept is fairly simple.
- First create two lists. One is to add Polls and the other is to store user's vote information.
- Let's call the first list as "Poll List" and the other as "User Poll List".
- Set "User Poll List" as a hidden list.
- In "Poll List", create seven additional columns. Title is already there when you have created it. List columns are,
- Title - string
- Answers - Check Box, Set Check Box values as Yes,No,Pass. So Poll publisher can select which answers should be there in each question
- Poll Created By - People Picker
- Date Started - Date and Time
- Date Expired - Date and Time
- Total Yes - Number and this column is disabled
- Total No - Number and this column is disabled
- Total Pass - Number and this column is disabled
- In "User Poll List", create one additional column. Again Title is already there. List columns are,
- Title - string
- Voter's Name - string
- Now Open Visual Studio 2010 and create a Visual Web Part.
- Put a some labels and set their text to empty and a Button. Let's name it as "Vote".
- Put a Radio Button List, so later we can fill the answer to it.
- Write method to get the last item in the "Poll List" which is not expired and call it in the Web Part Load event.
- Fill labels and fill the radio button list from the received data of the last item.
- Now in "Vote" Button click event we are going to insert user selected data to both lists.
- First query the "User Poll List" and check whether there is a item which the 'Title' is the current question and the 'Voter's Name' is the current logged on user's name. If there is, that means current logged on user has already voted for the selected question.
- If there is no item, that means he/she has not voted for this question yet. So first add a item to the "User Poll List" and then update (increase the value by 1) the 'Total Yes'/'Total No'/'Total Pass' field in the "Poll List" to the relevant question.
- And that's all. Now you might think that there will be a heavy load in the "User Poll List" as user's votes.
- For that when a question has expires, we will delete all relevant items in the "User Poll List". By doing that we can avoid getting "User Poll List" by overloading.
I have created a nice Polling Web Part using above steps. If you see any drawbacks of the above method, please feel free to post a comment and appreciating your feedback.
Happy Coding.
Regards,
Jaliya
Update - 06th December 2011
Hello guys, since a lot of people are asking for the source code of my Polling Web Part, I have uploaded the source. You can download it from here. Please note that, I have not uploaded the full source code. But I am pretty sure, you will find the provided source code interesting.
Update - 06th December 2011
Hello guys, since a lot of people are asking for the source code of my Polling Web Part, I have uploaded the source. You can download it from here. Please note that, I have not uploaded the full source code. But I am pretty sure, you will find the provided source code interesting.
Happy Coding.
Regards,
Jaliya
Can you give me a code for multiple choise poll webpart..
ReplyDeleteyes, that can be done. give me your details.
ReplyDeleteHappy Coding.
Regards,
Jaliya
This comment has been removed by the author.
DeleteHi there,
ReplyDeleteIf possible can I get as well, thanks
can you pls share the code for multiple choce poll webpart..
ReplyDeletepls send to
skarthikmca05@gmail.com
hi could you share the code for multiple choice poll webpart.
ReplyDeletewafonrc@gmail.com
Greetings...
Hi there, You have a nice implementation of a polling web part there. I managed to come up with a polling web part based on the steps you described, and its working great! I really appreciate it! However, I have a question, I am facing this problem of all my mutiple choices showing up in the web part when I only checked Yes and No during the creation of the poll. May I know how you retrieve the choices dynamically?
ReplyDelete-Chuwei limchuwei@gmail.com
Hi Jaliya! Thanks for your help on enlightening me earlier on. I managed to get the answers that were checked by the poll publisher. I retrieved the value from the list and did the following:
ReplyDeletestring delimStr = ";#";
char[] delimiter = delimStr.ToCharArray();
String[] answerslist = answers.Split(delimiter,StringSplitOptions.RemoveEmptyEntries);
and everything is working perfectly fine now! Thanks for all your help! :)
-Chuwei
Hi Chuwei,
ReplyDeleteI am glad you made it.
Happy Coding.
Regards,
Jaliya
Hi Jaliya,
ReplyDeletecan I get the source code, phebsix@gmail.com.
Thanks
Hi Jaliya,
ReplyDeleteCan you please send me the code. i would really appreciate it!
email- fuzzy528@gmail.com
Thanks,
faraz
It looks as though there is a high demand for the source code. Could you please send me the Code as well?
ReplyDeleteThank you so much,
adamwatson1.0@gmail.com
Hi Jaliya,
ReplyDeleteCan you please send me the code. i would really appreciate it!
email- darpanthedj@gmail.com
Thanks,
Darpan
Hello guys,
ReplyDeleteI have updated the post with the source code download link. If you think that the source code is interesting, Please put a comment. So others will find it helpful.
Thank You.
Happy Coding.
Regards,
Jaliya
Jaliya, Can you send help on with need to implement for Anonymous users...Can you please suggest and Share with coding
Deleteand the question and choices will be display on homepage for Anonymous..Can You please share with complete code ASAP...would u appriciate u...pls help me....dvmkrishna.2009@gmail.com
Man thats super cooool
ReplyDeleteWhat about the complete code
can you send it to system_by@yahoo.com
I have a similar requirememnt for creating polls or voting mechanism on sharepoint, however, one important requirement is that as ad administrator i must be able to set groups of people who can vote on a certain poll and the groups could be a combination of various things like office location, departments, etc. Any ideas?
ReplyDeleteemail me please : houji_zhou@yahoo.com
ReplyDeleteHi Jaliya,
ReplyDeleteIts very nice post,i have similar kind of requirement.
Can you please send complete code to venkey.choudam@gmail.com
Please download the source code from the provided link.
DeleteHappy Coding.
Regards,
Jaliya
Hi there,
ReplyDeleteWould you mind sending the source code to cfrankland@gmail.com?
Thanks very much!
Please download the source code from the provided link.
DeleteHappy Coding.
Regards,
Jaliya
Hi Jaliya, can you please send your source code to guttat19@comcast.net, will appreciate it very much
ReplyDeletePlease download the source code from the provided link.
DeleteHappy Coding.
Regards,
Jaliya
hi Jaliya,
DeleteThanks a lot to this source code....please send to me .ascx design code also
haribabu708@gmail.com
it is very nice.
ReplyDeletecan you pls send the code to hemalth485@gmail.com
Please download the source code from the provided link.
DeleteHappy Coding.
Regards,
Jaliya
Hi, Jaliya. Can you please send me the code to myprostyle@gmail.com
ReplyDeletePlease download the source code from the provided link.
DeleteHappy Coding.
Regards,
Jaliya
Nothing in my mailbox. Plz, try again. And copy to mcproxa@yandex.ru
DeleteHi Jaliya,
ReplyDeleteVery Very useful post !!!!!!!!!
I have the same requiremwnt for MOSS 2007
Is it possible to deploy the same webpart in MOSS 2007?
Plz help me....thanks in advance :)
And one more thing,You haven't mentioned about view results and view results as bar cahrt or pie chart in the Source Code....If you don't mind could you please mail me those code part? (Email ID:gvenkateshsun@gmail.com)
DeleteHi Jaliya Udagedara,
ReplyDeleteCan you give me the Polling code ???
If yes just send it to jaytjhin@yahoo.co.id
Thx b4
Best Regards,
JAY
Hi Jaliya Udagedara,
ReplyDeleteCould you please email me coude to anvar58@hotmail.com
I tried the link - it did not work. ASking me to log in. If you send it to me directly to my email I would really appreciate it.
Thank you,
Anvar
Hi Jaliya,
ReplyDeleteCould you also send the full sourcecode to dreweitin@yahoo.com
Thanks!
drew
Thats interesting.... but doing so we are coding for something that we already have OOTB called as Surveys.. Its like reinventing the wheel... so is there any way we can use Survey list and use it for polling ?? so that we can use most of sharepoint stuff and need not to worry about minute stuff a lot..
ReplyDeleteHi Jaliya,
ReplyDeleteCan you please send me the complete source code. we have same requirement with mutiple answers from multiline text.
email id: veeru.bikkina@gmail.com
Really appreciated all your help.
Thanks,
veeru
Hello Jaliya,
ReplyDeleteCould you send code for multiple answers to dezmond928@yahoo.com
Thanks very much!
Jaliya,
ReplyDeleteWe have a situation where we would like to have a weekly poll for a "Picture of the Week". How easy is it to reuse the same poll over and over again with this method?
My email is: scott.walton@hines.com
Thanks!
-Scott
Hello Jaliya,
ReplyDeleteCould you send code for multiple answers.
My Email is:balajimore1985@gmail.com
Thanks very much!
Hi,
ReplyDeleteWould you please send me a copy of the source. This web part is really what I'm looking for.
Please. Thanks.
Email: chesterben28@gmail.com
Hi,
ReplyDeletecan you please send me the full source code.
Thanks.
Email: gupta09chandan@gmail.com
I am working with my code as explained in this blog. What are the reporting options we can see? bar chart/pie chart/ export to excel???
ReplyDeleteHi,
ReplyDeleteWould you be able to share the source code of the Poll Webpart?
Email: itzpankaj@hotmail.com
Jaliya, Can you send help on with need to implement for Anonymous users...Can you please suggest and Share with coding
ReplyDeleteand the question and choices will be display on homepage for Anonymous..Can You please share with complete code ASAP...would u appriciate u...pls help and Mail me....dvmkrishna.2009@gmail.com
Heya! If this is working in Sharepoint Online 2013, I would love to get your Quick Poll web part! I've been trying to find/create one for a long time now and as I have no coding skills I have not been able to create anything. :-) So if it's working on SPO 2013 and you are willing to share it, please send it to xear09@gmail.com
ReplyDeleteThank you! :-)
Hello, can you email me the code if it works in SharePoint 2013. My email address is savio.dias@live.com
ReplyDeleteThanks a lot
Savio
Hai can you please send me the code to ankarao59@gmail.com
ReplyDeleteHi,
ReplyDeleteThanks for your post,
actually I want use online poll for internet site. there is no user specific. so could you please give some suggestion or source code then it will be very helpful.
my mail id is: madeswvimal@gmail.com
Thanks and Regards
S.Madeswaran