SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a custom list programatically. I want to add a field to it call User, this should be a lookup to the system Users. This will be like the default CreatedBy field.

How would I do this?

share|improve this question
up vote 4 down vote accepted

First connect to your list, then get the 'Fields' property which is of type SPFieldCollection, then call the 'Add' method. They key to answering your question is the SPFieldType enumerable. Check out this link to see what types of fields you can add

list.Fields.Add("User", SPFieldType.User, isRequired);

How to add a field

share|improve this answer
While this technically is correct, it might be helpful to include some more context for future users. :) – Kit Menke Nov 15 '12 at 14:47
Thanks, I updated with a little more info. – andrew.petersen15 Nov 15 '12 at 16:42

Your Answer


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.