Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

thanks

share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

[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);
  list.Update();
}
share|improve this answer
    
Thanx. Remember to mark answers made on behalf of others as CW –  Anders Rask Jun 7 '11 at 8:00
add comment

Itm["AssignedTo"] = new SPFieldLookupValue(Vti, "");

here vti is USserID or GroupID

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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