How to have a column contain multiple users
-
16-10-2019 - |
Question
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?
Solution
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();
}
}
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange