Create Choice Type Site Column using CSOM

Create Choice Type Site Column using CSOM Programmatically SharePoint

In this post, I described you to Create Choice Type Site Column using CSOM. Choice type column basically provides choice to end user. A choice takes input in button or drop down format. If you need to create number type field follow my post. Create Number Type Site Column using CSOM

Dropdown list Site Column

[AdSense-A]

ClientContext clientContext = new ClientContext(SiteUrls);
                Web rootWeb = clientContext.Site.RootWeb;
string schemaChoiceTypeField = "<Field ID='<GUID>' Type='Choice' DisplayName='Menu CHoice' Name='MenuChoice' StaticName='MenuChoice' 
   Format='Dropdown'>"
   + "<Default>Meat menu</Default>"
   +         "<CHOICES>"
   +         "    <CHOICE>Fish menu</CHOICE>"
   +         "    <CHOICE>Vegeterian menu</CHOICE>"
   +         "</CHOICES>"
   + "</Field>";
rootWeb.Fields.AddFieldAsXml(schemaChoiceTypeField , true, AddFieldOptions.AddFieldInternalNameHint);
clientContext.ExecuteQuery();

Radio buttons Site Column

string schemaChoiceField = "<Field ID='<GUID>' Type='Choice' Name='SideDishesChoice' StaticName='SideDishesChoice' 
   DisplayName='Side dishes' Format='RadioButtons'>"
   + "<Default>Patatoes</Default>"
   +         "<CHOICES>"
   +         "    <CHOICE>Fresh vegetables</CHOICE>"
   +         "    <CHOICE>Beans</CHOICE>"
   +         "</CHOICES>"
   + "</Field>";

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!