I need to retrieve some information from a FieldLookupValue using CSOM SharePoint2013 library. Specifically, I have a SPList and I need to populate a Field which type is Lookup. 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. 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
The following example demonstrates how to retrieve associated List for Predecessors
field from Tasks
list:
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.