[英]How to retrieve associated list name from a FieldLookupValue Sharepoint 2013 CSOM
I need to retrieve some information from a FieldLookupValue using CSOM SharePoint2013 library. 我需要使用CSOM SharePoint2013库从FieldLookupValue中检索一些信息。 Specifically, I have a SPList and I need to populate a Field which type is Lookup.
具体来说,我有一个SPList,我需要填充一个类型为Lookup的Field。 Is there a way to know the name of associated list?
有没有办法知道关联列表的名称? I know for sure that this information is contained in the FieldLookupvalue: if I create an instance of it using LookupID of associated Item SharePoint automatically associates the lists.
我肯定知道此信息包含在FieldLookupvalue中:如果我使用关联的Item的LookupID创建它的一个实例,SharePoint会自动关联列表。 Infact this code works well:
实际上,此代码运行良好:
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 does not expose any properties for getting associated list, but you could retrieve the associated list from a Lookup field FieldLookupValue类不会公开用于获取关联列表的任何属性,但是您可以从“ 查找”字段中检索关联列表
The following example demonstrates how to retrieve associated List for Predecessors
field from Tasks
list: 下面的示例演示如何从“
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.