0

I have site column called users based of people and groups and for example it has 4 users separated by semicolon.

Questions: 1) Can I copy the values from users site column to site permissions owner group.

2) How can i split users into multiple lines from users site columns, currently it is in one line with semicolon.

I really appreciate your response.

2 Answers 2

1

With the help of below code you can values from people sitecolumn and play as you want

SPList oList = new SPSite("http://devbox1:71").AllWebs["PCS"].GetList("http://devebox:71/PCS/Lists/UserList");

SPListItemCollection collListItems = oList.Items;         
SPListItem itemFound;         
if (oList.EnableVersioning)         
{             
    foreach (SPListItem oListItem in collListItems)             
    {                  
        string[] strName;
        string str = oListItem["UserField"].ToString();
        strName=str.Split('#');                 
        Console.Write(strName[0]);
     }
} 
1
  • It's worth noting that you'll have two memory leaks using this code sample. One for the SPSite & one for the SPWeb objects you open up. Apr 4, 2012 at 21:49
0

Try:

SPGroup group = web.AssociatedOwnerGroup;
SPFieldUserValueCollection users = 
    new SPFieldUserValueCollection(web, item["users"] as string);
foreach (SPFieldUserValue user in users)
{
    if (null != user.User) 
    {
        group.AddUser(user.User);
    }
}
group.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.