Link to home
Start Free TrialLog in
Avatar of Software Squirrel
Software SquirrelFlag for United States of America

asked on

Loop for PeopleEditor C#

I have a custom webpart that has 3 PeopleEditors on the form. This form submits to the custom list in SharePoint.  I have the code to update 1 of the PeopleEditors, but need to make this loop through 3 different people editors in the form.  Maybe a second class with my code that I could call?
string requestors = ppRequestor.CommaSeparatedAccounts;
            // commaseparatedaccounts returns entries that are comma separated. we want to split those up
            char[] splitter = { ',' };
            string[] splitPPReq = requestors.Split(splitter);
            // this collection will store the user values from the people editor which we'll eventually use
            // to populate the field in the list    
            SPFieldUserValueCollection values = new SPFieldUserValueCollection();
             // for each item in our array, create a new sp user object given the loginname and add to our collection
            for (int i = 0; i < splitPPReq.Length; i++)
            string loginName = splitPPReq[i];
            if (!string.IsNullOrEmpty(loginName))
            SPUser user = web.SiteUsers[loginName];
            // you could also use SPUser user = web.EnsureUser(loginName);
            SPFieldUserValue fuv = new SPFieldUserValue(web, user.ID, user.LoginName);
            string primaryAdmin = ppAdmin.CommaSeparatedAccounts;
    // set the Person or Group column
    newRequest["Requestor"] = values;

Open in new window

Avatar of Software Squirrel
Software Squirrel
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Software Squirrel