[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Loop for PeopleEditor C#

Posted on 2011-02-16
4
Medium Priority
?
1,607 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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