I want to add a attribute (Person or Group) in List through coding, does any one know how to do it.



[Saboor's comment re-posted as an answer, with minor modifications]

SPSite site = SPContext.Current.Site;
using (SPWeb web = site.OpenWeb())
  SPListCollection lists = web.Lists;
  SPList list = lists['Guid for List'];
  list.Fields.Add("people", SPFieldType.User, false);
  • Thanx. Remember to mark answers made on behalf of others as CW – Anders Rask Jun 7 '11 at 8:00
Itm["AssignedTo"] = new SPFieldLookupValue(Vti, "");

here vti is USserID or GroupID

  • Actually, I have created a list and wanted to add a column in it of people group type, not want to set values in it. – Saboor Awan Apr 4 '11 at 7:42
  • SPField Field = null; Field = currentWeb.Fields[FName]; List.Fields.Add(Field); – vipin Paliwal Apr 4 '11 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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