I have a survey list in sharepoint and I’d like to add an answer to the survey using c# code, this I think could be interpreted as add an item to the list so I tried the next but is not working.
How can this be done?
using (SPSite site = new SPSite("http://user-pc"))
{
using (SPWeb web = site.RootWeb)
{
try
{
SPList olist = web.Lists["JobSchedulle"]; //<- Name of the survey in sharepoint 2010
SPListItem item = olist.Items.Add();
item[5] = "good";// <- this survey only has one question, and is a text option ..
item.Update();
}
catch {
Console.ReadLine();
}
}
}
I found the error – the code works, but I was accessing
item[5](with the wrong index).