?
Solved

Loop for PeopleEditor C#

Posted on 2011-02-16
4
Medium Priority
?
1,594 Views
Last Modified: 2013-12-17
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);
            values.Add(fuv);
                
            string primaryAdmin = ppAdmin.CommaSeparatedAccounts;
        }
 
    }
 
    // set the Person or Group column
    newRequest["Requestor"] = values;

Open in new window

0
Comment
Question by:Christopher Gore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
Christopher Gore earned 0 total points
ID: 34928465
I solved it.
newRequest["Requestor"] = GetUsersFromPeopleEditor(ppRequestor.CommaSeparatedAccounts, web);
            newRequest["Reqestor2"] = GetUsersFromPeopleEditor(ppRequestor2.CommaSeparatedAccounts, web);
            newRequest["Requestor3"] = GetUsersFromPeopleEditor(ppRequestor3.CommaSeparatedAccounts, web);
            //---------End view section------------------
            newRequest.Update();
        }
        protected SPFieldUserValueCollection GetUsersFromPeopleEditor(string requestors, SPWeb web)
        {
            // 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);
                    values.Add(fuv);
                }
            }

            // set the Person or Group column
            return values;
        }

Open in new window

0
 
LVL 1

Author Closing Comment

by:Christopher Gore
ID: 34928469
Solved
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question