1

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?

  • Something is missing in your code... can you finish this line... – Toni Frankola May 25 '11 at 17:58
2

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();
    }
}
0

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.

  • 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

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.