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

share|improve this question
add comment

2 Answers 2

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]);
     }
} 
share|improve this answer
    
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. –  Tim Gabrhel Apr 4 '12 at 21:49
add comment

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();
share|improve this answer
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.