我需要使用 CSOM SharePoint2013 库从 FieldLookupValue 中检索一些信息。 具体来说,我有一个 SPList,我需要填充一个类型为 Lookup 的字段。有没有办法知道关联列表的名称?我确信此信息包含在 FieldLookup 值中:如果我使用关联项目的 LookupID 创建它的实例,SharePoint 会自动关联列表。事实上这段代码运行良好:
switch (field.TypeAsString)
{
case "Lookup":
int id = Convert.ToInt32(info);
FieldLookupValue lv = new FieldLookupValue() { LookupId = id };
newItem[field.InternalName] = lv;
break;
default:
// do nothing
break;
}
请您参考如下方法:
FieldLookupValue class不会公开任何用于获取关联列表的属性,但您可以从 Lookup field 中检索关联列表
以下示例演示如何从 Tasks 列表中检索 Predecessors 字段的关联列表:
using (var ctx = new ClientContext(webUri))
{
var list = ctx.Web.Lists.GetByTitle("Tasks");
var field = list.Fields.GetByInternalNameOrTitle("Predecessors");
var lookupField = ctx.CastTo<FieldLookup>(field);
ctx.Load(lookupField);
ctx.ExecuteQuery();
var lookupListId = new Guid(lookupField.LookupList); //returns associated list id
//Retrieve associated List
var lookupList = ctx.Web.Lists.GetById(lookupListId);
ctx.Load(lookupList);
ctx.ExecuteQuery();
}
