I would like to create a link list, and then add a choice column (Field) with two choices to the default view.
Using the following code i am able to create the list and add a column (Field) to the default view. I cant get the //CREATE FIELD part working:
// CREATE NEW LIST
ListCreationInformation newList12 = new ListCreationInformation();
// Titel
newList12.Title = "Links";
newList12.TemplateType = (int)ListTemplateType.Links; // Template
newList12.QuickLaunchOption = QuickLaunchOptions.Off; // Quicklaunch option
List list12 = web.Lists.Add(newList12);
newList12.Description = "Opret og del links";
// Update list + execute
list12.Update();
context.ExecuteQuery();
//CREATE FIELD
List listUpdate12 = web.Lists.GetByTitle("Links");
listUpdate12.Fields.Add("Field Name", FieldType.Choice, false);
//Get Field Reference
FieldChoice col = (FieldChoice)listUpdate12.Fields.GetByTitle["Field Name"];
col.Choices.Add("option 1");
col.Choices.Add("option 2");
col.DefaultValue = "option 1"; //otherwise blank row by default.
col.update(); //Saves choices to column
listUpdate12.Update();
// ADD FIELD TO VIEW
View view12 = list12.Views.GetByTitle("All Links");
view12.ViewFields.Add("Field Name");
// update view + list
view12.Update();
list12.Update();
context.ExecuteQuery();
When i hower the "listUpdate12.Fields.Add("Field Name", FieldType.Choice, false);" part i get: Error: No overload method "Add" takes 3 arguments.
When i hower the "listUpdate12.Fields.GetByTitle["Field Name"];" part i get: Cannot apply indexing with [] to an expression of type 'method group'.
Any suggestions?