Application Modernization Industry Quick Guides
Application modernization enables you to optimize business processes and transform the way you do business today, and in the future. Our industry experts have collected the latest application modernization trends impacting the automotive, financial services, healthcare, and manufacturing verticals.
I was recently working on some code that added items to a SharePoint list based on a user’s input from an InfoPath form. It was an easy task until I got to a choice column. I wasn’t sure of the syntax for setting the value of a choice column, and for some reason, all of the blog posts I found focused on adding values to a choice column. After some trial and error, I figured out this solution.
using (SPSite site = new SPSite("http://mysite.local/"))
using (SPWeb web = site.OpenWeb())
SPList list = web.Lists["My List"];
string myChoice = “My Choice”;
SPListItem item = list.Items.Add();
item["Choice Column"] = list.Fields["Choice Column"].GetFieldValue(myChoice);
As long as the value of the parameter passed into GetFieldValue() matches an existing value in the choice column, a new list item will be added with the specified value in the choice column.