This is a nice snippet I saw and will like to share Let us assume we have two list aList and bList already created. Requirement is to create a lookup column in aList which will look up values in bList. SPList aList = web.Lists["aList"]; SPList bList = web.Lists["bList"]; aList.Fields.AddLookup("Lookup", bList.ID, false); SPFieldLookup fldLookup = aList.Fields["Lookup"] as SPFieldLookup; fldLookup.LookupField = bList.Fields[SPBuiltInFieldId.Title].InternalName; fldLookup.Update();
Cloud development @ its best. Snippets, ideas, latest, best practices etc.