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 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

1 Answer 1

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

 
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.