1

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?

2
  • Through the UI or through code?
    – Colin
    Commented Jun 9, 2011 at 21:05
  • OM would suggest object model - I'll update the title to make that clear.
    – Andy Burns
    Commented Jun 10, 2011 at 8:48

1 Answer 1

3
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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.