如何使用SharePoint C#ConsoleApp在任何一个列表中添加与字段(每个列表中的字段将不同)对应的值
当列表具有不同的字段且字段的字段类型不同时,如何循环get field以替换listItem[“Title”]=listItem[列表中的字段]并读取列表中相应的字段如何使用SharePoint C#ConsoleApp在任何一个列表中添加与字段(每个列表中的字段将不同)对应的值,c#,sharepoint,console-application,C#,Sharepoint,Console Application,当列表具有不同的字段且字段的字段类型不同时,如何循环get field以替换listItem[“Title”]=listItem[列表中的字段]并读取列表中相应的字段 string listNameAnything = console.ReadLine(); string inputValueAnything = console.ReadLine(); List list = clientContext.Web.Lists.GetByTitle(listNameAnything);
string listNameAnything = console.ReadLine();
string inputValueAnything = console.ReadLine();
List list = clientContext.Web.Lists.GetByTitle(listNameAnything);
ListItemCreationInformation newItem = new ListItemCreationInformation();
ListItem listItem = list.AddItem(newItem);
listItem["Title"] = inputValueAnything;
//WHat I need to handle it
listItem.Update();
clientContext.ExecuteQuery();
您可以尝试使用以下脚本获取所有字段名:
ContentTypeCollection contentTypes = list.ContentTypes;
ctx.Load(contentTypes);
ctx.ExecuteQuery();
ContentType contentType = contentTypes[0];
FieldCollection fields = contentType.Fields;
ctx.Load(fields);
ctx.ExecuteQuery();
foreach(Field field in fields)
{
Console.WriteLine("field type:"+field.TypeAsString + "; field name :"+ field.Title);
}