Access to survey data in SharePoint

Question from a forum:

I need help to access to a SharePoint Survey data programmatically. Every
month the user make a draw picking up 3 winners from all the users that have
been answered the survey.How can I access to the “created” and “create by” field
of the list?

Surveys are little more than complex lists, so anything you can do to lists, such as getting the author of a particular item, can be done to a survey. Check out the following code sample:

    1 using (SPSite site = new SPSite(http://lab-s02:12000/))
    2             {
    3 using (SPWeb web = site.OpenWeb())
    4                 {
    5 SPList survey = web.Lists["TestSurvey"];
    6 SPListItemCollection items = survey.Items;
    7 foreach (SPListItem item in items)
    8                     {
    9 string author = item["Author"].ToString();
   10 DateTime create = (DateTime)item["Created"];
   12                     }
   14                 }
   15             }

Found this article valuable? Want to show your appreciation? Here are some options:

a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.

b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.

c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!

Pin It

Published by

Bjørn Furuknap

I previously did SharePoint. These days, I try new things to see where I can find the passion. If you have great ideas, cool projects, or is in general an awesome person, get in touch and we might find out together.

4 thoughts on “Access to survey data in SharePoint”

  1. OK, thats easy. But how can you get the questions, since a text question and the filetype-field have both the type text?

  2. Hi,

    I know this is too late to ask, but couldn’t find any other sites where this was explained better than this. I have a Survey in SP 2010, with settings to hide users’ names in survey results. Now, when i try to get the responses, same way as you explained, i get only “***” as the name for Authors. Any idea if there is a way out?

Leave a Reply

Your email address will not be published.