How to create questions for survey programmatically?

laputa.sky - Posted on 2008年8月4日 21:53:40

With branch for questions,an example will be perfect.
--------------------------------------------------------------------------------


AnswerSharePoint EnthusiastMVP - Posted on 2008年8月4日 22:21:05

You can programmatically add questions to sharepoint survey (list). Refer the following code

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);

survey.Update();
web.Update();

I've not tried creating a branching question programmatically. Even that should be possible programmatically.

 

 

-------------------

分支可以通过修改Field的SchemaXMl来实现

后期给出代码

posted @ 2008-09-25 22:35  laputa'sky  阅读(218)  评论(0编辑  收藏  举报