Saturday, August 23, 2008

Surveys Add questions.


Surveys Add questions programatically

SurveysSPListTemplate objTemplate = currentWeb.ListTemplates["mySurvey"];
Guid objGuid = currentWeb.Lists.Add("mycode", "survey", objTemplate);
SPList objSurvey = currentWeb.Lists["mycode"];
//Let’s add questions
StringCollection strQuestions = new StringCollection();
string strQuestion = "What is your favrate colour?";
strQuestions.Add("Red");strQuestions.Add("Blue");
strQuestions.Add("Green");
objSurvey.Fields.Add(strQuestion, SPFieldType.Choice, true, false, strQuestions);
objSurvey.AllowMultiResponses = false;objSurvey.Update();

No comments: