static void CreateNormalSiteColumns(ClientContext cContext, string displayname, string internalname, string group, string type) { FieldType fieldType = new FieldType(); if (type == "Text") { fieldType = FieldType.Text; } if (type == "Note") { fieldType = FieldType.Note; } if (type == "Integer") { fieldType = FieldType.Integer; } if (type == "DateTime") { fieldType = FieldType.DateTime; } if (type == "Number") { fieldType = FieldType.Number; } if (type == "Choice") { fieldType = FieldType.Choice; } if (type == "Boolean") { fieldType = FieldType.Boolean; } if (type == "Currency") { fieldType = FieldType.Currency; } // Field Creation Parameters OfficeDevPnP.Core.Entities.FieldCreationInformation newFieldInfo = new OfficeDevPnP.Core.Entities.FieldCreationInformation(fieldType) { DisplayName = displayname, InternalName = internalname, Group = group, Id = Guid.NewGuid() }; // Creates new Field Field newField = cContext.Site.RootWeb.CreateField(newFieldInfo); Console.WriteLine("New Site Column" + newField.Title + " has been created"); }
//gavdcodeend 04 //gavdcodebegin 05 static void SpCsPnpcoreAddOneFieldToList(ClientContext spCtx) { Web myWeb = spCtx.Web; List myList = myWeb.Lists.GetByTitle("NewListPnPCore"); FieldType fieldType = FieldType.Text; OfficeDevPnP.Core.Entities.FieldCreationInformation newFieldInfo = new OfficeDevPnP.Core.Entities.FieldCreationInformation(fieldType) { DisplayName = "NewFieldPnPCoreUsingInfo", InternalName = "NewFieldPnPCoreInfo", Id = new Guid() }; myList.CreateField(newFieldInfo); string fieldXml = "<Field DisplayName='NewFieldPnPCoreUsingXml' " + "Type='Note' Required='FALSE' Name='NewFieldPnPCoreXml' />"; myList.CreateField(fieldXml); }
private void button11_Click(object sender, EventArgs e) { using (var context = new ClientContext("https://thethread-qa.carpetright.co.uk/Facilities/")) { try { var web = context.Web; List list = null; var lci = new ListCreationInformation(); lci.Title = "Project Documents"; lci.QuickLaunchOption = QuickLaunchOptions.On; lci.TemplateType = (int)ListTemplateType.DocumentLibrary; list = web.Lists.Add(lci); FieldType fieldType = FieldType.Number; OfficeDevPnP.Core.Entities.FieldCreationInformation newFieldInfo = new OfficeDevPnP.Core.Entities.FieldCreationInformation(fieldType); newFieldInfo.DisplayName = "Year"; newFieldInfo.AddToDefaultView = true; newFieldInfo.InternalName = "Year"; newFieldInfo.Id = Guid.NewGuid(); list.CreateField(newFieldInfo, false); context.ExecuteQuery(); var status = "Field Created"; ResultsListBox.Items.Add(list.Title + status); } catch (Exception ex) { ResultsListBox.Items.Add(ex.Message); } } }