如何使用 SharePoint C# ConsoleApp 在任何一个列表中添加与字段对应的值(每个列表中的字段将不同)
How to Add Value corresponding to the field (The field in each list will be different) in any one list with SharePoint C# ConsoleApp
如何循环获取字段来替换listItem["Title"] = listItem[列表中的字段],当列表中的字段不同且字段的字段类型不同时,如何读取列表中的相应字段
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);
}
如何循环获取字段来替换listItem["Title"] = listItem[列表中的字段],当列表中的字段不同且字段的字段类型不同时,如何读取列表中的相应字段
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);
}