Programmatically Create SharePoint Survey questions


I’m seeing this question “Is there way to create SharePoint Survey questions programmatically ?” many times in SharePoint Forums and News Groups


The answer is that it’s definitely achievable programmatically through SharePoint API’s. The following snippet would help.

SPWeb web = SPControl.GetContextWeb(HttpContext.Current);

Guid surveyId = web.Lists.Add(“Name of the Title”, “Description of the survey”, SPListTemplateType.Survey);

SPList survey = web.Lists[“Survey List Name or Id];

string Question = “Question#1 for survey”;

StringCollection choices = new  StringCollection();

choices.Add(“first choice”);

choices.Add(“second choice”);

choices.Add(“third choice”);

survey.Fields.Add(Question, SPFieldType.Choice, true, false, choices);


 Subscribe to my post

8 thoughts on “Programmatically Create SharePoint Survey questions

  1. I have a webpart that already build list survey type, now ,i like to know how to answer those questions , but in the same way, i mean programmatically. The problem is that i build the webpart via render, and the controls for the answer too.
    So, how answer the questions dinamically in run time.

  2. yes you can programmatically find the whether the survey has questions or not. Each survey question is internally stored as content type.
    I think by default a survey list would have 42 fields in the field-collection(without any question). If the field collection has more than 42 items, then obviously it has questions attached to it

  3. It is a very good article. Now I’m trying to put a page separator to separate my questions in the survey but i’m having some problems with that. Can someone give some help on that?


Leave a Reply