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"];
   11 
   12                     }
   13 
   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