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 a list with various columns. One of those columns is to store users. However, when I use the code

configurationListFields.Add("Limit_Access_To", SPFieldType.User);

I am only allowed to enter one user. How can I change this so I can enter multiple users or groups?

share|improve this question
    
Something is missing in your code... can you finish this line... –  Toni Frankola May 25 '11 at 17:58
add comment

2 Answers 2

up vote 1 down vote accepted

Here's how you'd do it via code (note: solution does not provide error checking)

using (SPSite siteColl = new SPSite("http://yourSPSite"))
{
    using (SPWeb site = siteColl.OpenWeb())
    {
        SPList customList = site.Lists.TryGetList("Your List Name");
        SPFieldCollection fieldColl = customList.Fields;
        SPFieldUser userField = (SPFieldUser)fieldColl.GetField("ColumnName");
        userField.AllowMultipleValues = true;
        userField.Update();
    }
}

And a slightly shorted version:

using (SPSite siteColl = new SPSite("http://yourSPSite"))
{
    using (SPWeb site = siteColl.OpenWeb())
    {
        SPList customList = site.Lists.TryGetList("Your List Name");
        SPFieldUser userField = (SPFieldUser)customList.Fields["ColumnName"];
        userField.AllowMultipleValues = true;
        userField.Update();
    }
}
share|improve this answer
add comment

Is the column defined to allow multiple values? Go into the list settings, click the person/group column and change the allow multiple selections to Yes.

share|improve this answer
    
It is not selected. I would like to do this programmatically using C# if possible. Do you know how to set Allow multiple selections to Yes using C#? –  Meyer Denney May 25 '11 at 18:05
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.