Question

I have an existing list "Country List", Column "COUNTRY" contains name of the all the countries.

I would like to create a look up field "Origin Country" in a list "Order List" via OM. How do I do that?

Was it helpful?

Solution

var list = web.Lists["Order List"];
var targetList = web.Lists["Country List"];
var fieldName = list.AddLookup("Origin Country", targetList.ID, true);
var field = list.Fields.GetByInternalName(fieldName) as SPFieldLookup;
field.LookupField = targetList.Fields["COUNTRY"].InternalName;
field.Update();
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top