Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Security;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SharePoint.Client;
- namespace CSOMOffice365
- {
- class Program
- {
- static void Main(string[] args)
- {
- string userName = "[email protected]";
- Console.WriteLine("Enter your password.");
- SecureString password = GetPassword();
- // ClienContext - Get the context for the SharePoint Online Site
- // SharePoint site URL - https://c986.sharepoint.com
- using (var clientContext = new ClientContext("https://c986.sharepoint.com"))
- {
- // SharePoint Online Credentials
- clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
- // Get the SharePoint web
- Web web = clientContext.Web;
- // Get the list by Title
- List list = web.Lists.GetByTitle("Custom");
- // Get a specific field by Title
- Field field = list.Fields.GetByTitle("Choice");
- FieldChoice fieldChoice = clientContext.CastTo<FieldChoice>(field);
- clientContext.Load(fieldChoice);
- // Execute the query to the server
- clientContext.ExecuteQuery();
- // Add the choice field values
- List<string> options = new List<string>(fieldChoice.Choices);
- options.Add("Option1");
- options.Add("Option2");
- options.Add("Option3");
- fieldChoice.Choices = options.ToArray();
- // Update the choice field
- fieldChoice.Update();
- // Execute the query to the server
- clientContext.ExecuteQuery();
- // Display all the choices
- foreach (string option in fieldChoice.Choices)
- {
- Console.WriteLine(option);
- }
- Console.ReadLine();
- }
- }
- private static SecureString GetPassword()
- {
- ConsoleKeyInfo info;
- //Get the user's password as a SecureString
- SecureString securePassword = new SecureString();
- do
- {
- info = Console.ReadKey(true);
- if (info.Key != ConsoleKey.Enter)
- {
- securePassword.AppendChar(info.KeyChar);
- }
- }
- while (info.Key != ConsoleKey.Enter);
- return securePassword;
- }
- }
- }
Output

vishal patilPosted Oct 8, 2018, 2:50 AM
If i want to add option4 insted of A(basically i want to rewrite the choice field) from output then what is the solution....
Surya Prakash PandeyPosted Nov 25, 2016, 8:42 AM
Nice article buddy ... solved my issue thank you so much .. :)
Bhuvanesh MohankumarPosted May 18, 2016, 7:44 AM
Good one...
Ketak BhalsingPosted May 17, 2016, 1:55 AM
Good info....