Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Security;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Microsoft.SharePoint.Client;
  9. namespace CSOMOffice365
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. string userName = "[email protected]";
  16. Console.WriteLine("Enter your password.");
  17. SecureString password = GetPassword();
  18. // ClienContext - Get the context for the SharePoint Online Site
  19. // SharePoint site URL - https://c986.sharepoint.com
  20. using (var clientContext = new ClientContext("https://c986.sharepoint.com"))
  21. {
  22. // SharePoint Online Credentials
  23. clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
  24. // Get the SharePoint web
  25. Web web = clientContext.Web;
  26. // Get the list by Title
  27. List list = web.Lists.GetByTitle("Custom");
  28. // Get a specific field by Title (TestCol - Single line of text)
  29. Field field = list.Fields.GetByTitle("TestCol");
  30. // Update the field type to multi line of text
  31. field.TypeAsString = "Note";
  32. field.Update();
  33. clientContext.Load(field);
  34. // Execute the query to the server
  35. clientContext.ExecuteQuery();
  36. // Display the field name and type
  37. Console.WriteLine(field.Title + " -- Field Type updated to : " + field.TypeAsString);
  38. Console.ReadLine();
  39. }
  40. }
  41. private static SecureString GetPassword()
  42. {
  43. ConsoleKeyInfo info;
  44. //Get the user's password as a SecureString
  45. SecureString securePassword = new SecureString();
  46. do
  47. {
  48. info = Console.ReadKey(true);
  49. if (info.Key != ConsoleKey.Enter)
  50. {
  51. securePassword.AppendChar(info.KeyChar);
  52. }
  53. }
  54. while (info.Key != ConsoleKey.Enter);
  55. return securePassword;
  56. }
  57. }
  58. }
Output