Returning Name and Username from People Picker Field in Visual Web Part

Dear All
I am creating a visual web part that displays a list that I have created in SharePoint. One of the fields in the list is a People & Groups column type (People Picker) called 'Presented by'. In my web part, I would like to display the username and
the name of the person who has been 'picked' in this field. However, my using <%# Eval("Presented by") %> only displays their name. How do I get this field to also return their username?
Many thanks for your help
Daniel

You ca  use this code:- change it according to your need
int requestForUserID = 0;
string requestForUserLoginName = string.Empty;
string requestForUserName = string.Empty;
string userAccount = peoplePickerEmployee.CommaSeparatedAccounts;
string[] UsersSeperated = peEmployeeOnBehalf.CommaSeparatedAccounts.Split(',');
foreach (string user in UsersSeperated)
SPContext.Current.Web.EnsureUser(user);
SPUser spUser = SPContext.Current.Web.SiteUsers[user];
requestForUserID = spUser.ID;
requestForUserLoginName = spUser.LoginName;
requestForUserName = spUser.Name;
Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
INSQLSERVER.COM
Mohammad Nizamuddin

Similar Messages

  • Add Users from people picker field to sharepoint group

    Hi,
    I have created infopath form and added people picker control and then created data connection to add users to sharepoint group.
    Used UserGroup webservice and "AddUserToGroup" operation. If I select single user in people picker and click submit button, web service data connection adding user to sharepoint group without any issue but it's not working for multiple users.If
    I select multiple users in people picker, web service adding only first user to sharepoint groups. In our company we do not prefer custom coding.
    Can anybody help me out to resolve this issue?
    Any help or suggestions would be appreciated.
    Thank you,
    AA.

    You ll be able to achieve this by placing people picker in repeating table control in the form, below url may help you. 
    http://infopath.wordpress.com/2013/04/02/people-picker-email-addresses-repeating-tables-infopath-2010/
    Sivabalan

  • SharePoint 2013 Client Side People Picker in Content Editor Web Part

    Has anyone tried to use the client side people picker in a content editor web part? I have successfully got it to work in IE by adding all the script references and initialize function to the content editor web part. Now the strange part is, the people
    picker doesn't render in other browsers, I tried in Chrome, Safari, and Firefox. Any ideas?

    Below can be used to create people picker in CEWP
    <asp:content contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js" type="text/javascript"></script> 
       <script type="text/javascript" src="../Apps/_layouts/15/clienttemplates.js"></script> 
       <script type="text/javascript" src="../Apps/_layouts/15/clientforms.js"></script> 
       <script type="text/javascript" src="../Apps/_layouts/15/clientpeoplepicker.js"></script> 
       <script type="text/javascript" src="../Apps/_layouts/15/autofill.js"></script> 
       <script type="text/javascript" src="../Apps/_layouts/15/sp.js"></script> 
       <script type="text/javascript" src="../Apps/_layouts/15/sp.runtime.js"></script> 
       <script type="text/javascript" src="../Apps/_layouts/15/sp.core.js"></script> 
       <script type="text/javascript">
    <!-- Add your CSS styles to the following file -->
    <link rel="Stylesheet" type="text/css" href="../SiteAssets/PeoplePicker/App.css"/>
    <!-- Add your JavaScript to the following file -->
    // Run your custom code when the DOM is ready.
    $(document).ready(function () {
        // Specify the unique ID of the DOM element where the
        // picker will render.
        initializePeoplePicker('peoplePickerDiv');
    // Render and initialize the client-side People Picker.
    function initializePeoplePicker(peoplePickerElementId) {
        // Create a schema to store picker properties, and set the properties.
        var schema = {};
        schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
        schema['SearchPrincipalSource'] = 15;
        schema['ResolvePrincipalSource'] = 15;
        schema['AllowMultipleValues'] = true;
        schema['MaximumEntitySuggestions'] = 50;
        schema['Width'] = '280px';
        // Render and initialize the picker. 
        // Pass the ID of the DOM element that contains the picker, an array of initial
        // PickerEntity objects to set the picker value, and a schema that defines
        // picker properties.
        this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
    // Query the picker for user information.
    function getUserInfo() {
        // Get the people picker object from the page.
        var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;
        // Get information about all users.
        var users = peoplePicker.GetAllUserInfo();
        var userInfo = '';
        for (var i = 0; i < users.length; i++) {
            var user = users[i];
            for (var userProperty in user) { 
                userInfo += userProperty + ':  ' + user[userProperty] + '<br>';
        $('#resolvedUsers').html(userInfo);
        // Get user keys.
        var keys = peoplePicker.GetAllUserKeys();
        $('#userKeys').html(keys);
    </script>
    </asp:content> 
    <asp:content contentplaceholderid="PlaceHolderMain" runat="server">
    <div id="peoplePickerDiv"></div>
        <div>
            <br/>
            <input type="button" value="Get User Info" onclick="getUserInfo()"></input>
            <br/>
            <h1>User info:</h1>
            <p id="resolvedUsers"></p>
            <h1>User keys:</h1>
            <p id="userKeys"></p>
        </div>
    </asp:content>​​​​​​​​​
    Vishnu

  • People Picker field and Web service -- multiple round trips to get Display Name value

    Using Sharepoint 2010 and Infopath 2010, I have created a form that validates fields entered within the form by connecting to a .Net web service created  by someone else.  One of the fields that I need to validate is a People Picker field
    for the Project Manager. 
    The connection to the Web Service runs correctly except that the People Picker goes through the validation process 3-4 times.   I know this because I have a MessageBox showing the value for the InnerXML that pops up 3 times.  The
    first time the MessageBox shows no value for the XML, the next time it shows a name, and the 3rd time it shows no value.
    Here is the code I'm using in the Infopath form (without the Messagebox):
    Dim wsConnection As WebServiceConnection = DirectCast(Me.DataConnections("Validate"), WebServiceConnection)
    Dim formNavigatorProjectManager As XPathNavigator = MainDataSource.CreateNavigator()
    Dim wsNavigatorProjectManager As XPathNavigator = Me.DataSources("Validate").CreateNavigator()
    strformNavProjectManager = formNavigatorProjectManager.SelectSingleNode("/pr:properties/p:properties/documentManagement/ns3:ProjectManager/ns3:UserInfo/ns3:DisplayName", NamespaceManager).InnerXml
    wsNavigatorProjectManager.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns7:Validate/ns7:projectManager", NamespaceManager).SetValue(strformNavProjectManager)
    wsConnection.Execute()
    The line in BOLD above used to have just /pr:properties/p:properties/documentManagement/ns3:ProjectManager
    but I thought my problem might be because People Picker fields are made up of 3 elements -- DisplayName, AccountID and Account Type. So I changed the XML.  Sadly, that didn't make any difference.
    I am using the CHANGED event which a colleague of mine thought would have taken care of the multiple round trips.  But it didn't.
    Hopefully someone out there can tell me what I need to do so that this People Picker field only get validated once (The form also has Managed Metadata fields that have very similar problems so I'm hoping that the solution for the People Picker field
    takes care of the MMD fields too.)  Thanks in advance.  Carol.

    Hi Carol,
    It is the behavior for setting People/Group field if you just select the node "/dfs:myFields/dfs:queryFields/ns7:Validate/ns7:projectManager".
    Also you can try to only set the AccountID value of the People/Group field:
    Dim wsConnection As WebServiceConnection = DirectCast(Me.DataConnections("Validate"), WebServiceConnection)
    Dim formNavigatorProjectManager As XPathNavigator = MainDataSource.CreateNavigator()
    Dim wsNavigatorProjectManager As XPathNavigator = Me.DataSources("Validate").CreateNavigator()
    strformNavProjectManagerID = formNavigatorProjectManager.SelectSingleNode("/pr:properties/p:properties/documentManagement/ns3:ProjectManager/ns3:UserInfo/ns3:AccountID", NamespaceManager).InnerXml
    wsNavigatorProjectManager.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns7:Validate/ns7:projectManager/ns7:userinfo/ns7:AccountID", NamespaceManager).SetValue(strformNavProjectManagerID)
    wsConnection.Execute()
    Thanks,
    Eric
    Forum Support
    Please remember to mark the replies as answers
    if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]
    Eric Tao
    TechNet Community Support

  • Is there a way to exclude temporary people picker fields from a query when receiving the "List View Lookup Threshold" error.

    Hi All,
    My users require the ability to select a sharepoint group from a drop down list and then be able to select a user from a people picker based on the drop down selection.    The best solution I was able to up with, was create a people picker
    for each drop down selection and set the Sharepoint group field to the selected group.  All people picker filed are hidden except the one that matches the drop down selection.  When creating an entry from the sharepoint list this method
    works perfectly.
    However, when I add the list onto a site page using an "Listview webpart", then add an infopath web part and then finally connect the two parts, I get a "List View Lookup Threshold" error when selecting an entry from the list.  I
    understand from the error and reading that this error is related to the number of People pickers in the list.   Is there a way to exclude temporary people picker fields from a site page query, as they are only temporary fields to allow the users
    to select a person and then assign the name to another field.
    Dwayne

    Hi Dwayne,
    In SharePoint 2013, we could manually create a list for all users. Here are the reference:
    Go to Site Settings >  People and Groups > SiteMembers
    Modify url
    http://sitename/_layouts/15/people.aspx?MembershipGroupId=8 to
    http://sp/sites/tutu/_layouts/15/people.aspx?MembershipGroupId=0 , now you will see All people in this site.
    Change the view to List view, and copy the listview id in the url
    http://sitename/_layouts/15/people.aspx?MembershipGroupId=0&View={viewID}
    Go to Settings > List settings, copy the list id in the url
    http://sitename/_layouts/15/listedit.aspx?List=listeid&Source=....
    Now type the address in IE:
    http://sitename/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List=[LISTID]&View=[VIEWID]&CacheControl , such as
    http://sp/sites/tutu/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List=f3958d27-9c2f-4f8d-b221-89466e816667&View=696BFDC5-0C6E-4E27-818F-0E6292A18407&CacheControl=1
    Save the owssvr.jqy from SharePoint site
    Now you could see the file in your desktop with all users, save it as allusers in Excel.
    Then import it to your SharePoint site, add an app > find an app > import spreadsheet
    Regards,
    Rebecca Tu
    TechNet Community Support

  • Auto update people picker value with email id when we add username in another people picker field in sharepoint 2013 list using javascript

    hi friends
    i have to people picker fields
    pp1 and pp2
    pp1 represents username
    pp2 represents email id
    here i problem is if user enters name in pp1, pp2 has to update with email id of corresponding user in pp1 dynamically.
    using java script is there any solution for this.
    please help me

    Hope below will help
    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <script type="text/ecmascript" language="ecmascript">
    var user;
    var visitorsGroup;
    function runCode() {
    var clientContext = new SP.ClientContext();
    var groupCollection = clientContext.get_web().get_siteGroups();
    // Get the visitors group, assuming its ID is 4.
    visitorsGroup = groupCollection.getById(4);
    user = clientContext.get_web().get_currentUser();
    var userCollection = visitorsGroup.get_users();
    userCollection.addUser(user);
    clientContext.load(user);
    clientContext.load(visitorsGroup);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    function onQuerySucceeded() {
    alert(user.get_title() + " added to group " + visitorsGroup.get_title());
    function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    </script>
    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />
    </asp:Content>http://msdn.microsoft.com/en-us/library/office/jj246835%28v=office.15%29.aspxhttp://msdn.microsoft.com/en-us/library/office/jj920104%28v=office.15%29.aspxhttp://stackoverflow.com/questions/20981226/sharepoint-2013-get-current-user-javascripthttp://sharepoint.stackexchange.com/questions/31457/get-user-via-javascript-client-object-model

  • My contacts all got deleted from my phone, and was replaced with names and numbers of people I've never met before.

    My phone was working as normal, then all of a sudden when I checked my text messages all the names of my contacts got replaced by their actual phone numbers. When I checked my contacts, it looks like everyone got deleted from my phone, and was replaced with names and numbers of people I've never met before. Even when I check my icloud for a backup it has the same issue. I don't know how this is possible and not certain as to how to rectify and get my contacts back.

    Hi Also iPhone, need update to ios 8.1.2 do this over WiFi Use same Apple ID & Password. Cheers Brian

  • SharePoint 2013 July 2014 CU - People Picker fields empty in Edit forms

    After applying the July 2014 CU for SharePoint server, I discovered that Person or Group (People Picker) fields are not populated with server values in list item Edit forms.  However, the field values can be viewed in list views
    and in Display forms.  I examined the client side code and determined that field data is not being returned from the server for Edit forms. 
    In a test environment, I uninstalled SharePoint 2013, reinstalled SP 2013 with SP1 and the issue went away.  I then applied the May 2014, June 2014, and July 2014 CUs.  The issue did not exist after applying the May and June CUs.  It
    did exist after applying the July 2014 CU.

    There is a workaround for this issue.  It's a little convoluted, but hey, it's SharePoint.  First, you must have a list that has at least one entry in it.
     To begin with, you must first
    have a list with at least one item in the list.
    Next you edit the item with a role that has at least Design privilege, but don't save your changes.
    Instead you Edit the page so you can then edit that web part.  You can edit the page by clicking on the cog icon and selecting Edit Page
    Edit the web part itself
    Under “Miscellaneous” section on the just exposed web part window, select "Server Render (Server Render)" in the drop down labeled “CSR Render Mode
    Click on “Apply” button within the web part
    Save
    I was told also the Sept CU would fix the issue but it is under review and to wait until the first of October.  Incidentally we found that if you put the entire list into Quick Edit mode, the issue does
    not appear.
    I hope this helps someone.

  • How to make a people picker field editable using Javascript

    Hi All,
    I wrote an javascript which populates current loggedin user name on to an people picker, which is working fine,
       But its making the people picker field as readonly, i want this field to be editable so that i can add more users with the current loggedin user name already populated in the newform.aspx
    below is the script what i have written
    <script src="/_catalogs/masterpage/MashreqMasterpage/scripts/jquery-1.5.1.min"></script><script type="text/javascript" src="/_catalogs/masterpage/MashreqMasterpage/scripts/jquery.SPServices-0.7.1a.min.js"></script><script
    type="text/javascript">
     $(document).ready(function() {
         var user= $().SPServices.SPGetCurrentUser({fieldName: "Title"});
          $("div[title='Name']").text(user);
    </script>
    please help, thanks in advance

    Hi,
    Please modify your code a bit as below, it won’t make the people picker control read only after setting a value:
    var controlName = "MyPersonField";
    // Select the People Picker DIV
    var ppDiv = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");
    // find the <input> under pp DIV
    var ppEditor = ppDiv.find("[title='" + controlName + "']");
    // Get the instance of the People Picker from the Dictionary
    var spPP = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv[0].id];
    ppEditor.val(user);
    spPP.AddUnresolvedUserFromEditor(true);
    Best regards
    Patrick Liang
    TechNet Community Support

  • "People Picker" field not letting update SP linked table in Access

    Hello all,
    I have linked a SharePoint list to an Access database in order to manipulate some data. This list contains several fields, including a people picker in which its data come from SharePoint. 
    Once in my Access DB, I need to update some fields of this list, however when I try to change some values from a record that has the people picker populated I get the following error message: "you cannot reference rows created
    when you are disconnected from the server because this violates the lookup settings defined for this table". I only get this when I have values on people picker, I can proceed without any problem when I have it set as blank.
    So, do you have any idea on how to accomplish an update operation while having a people picker field populated?
    Thank you in advance.

    Hi Pedro,
    I recommend to check if the user populated in the RequestBy exits in User Information List in SharePoint site and the choices listed in Access for status field are existed in SharePoint Status column.
    Please refer to this thread for more details:
    https://social.technet.microsoft.com/Forums/office/en-US/8a7baf3b-5a3a-4631-82f9-b43d992155d1/updating-sharepoint-2010-list-from-access-2007?forum=sharepointgenerallegacy
    More reference:
    http://blog.incworx.com/blog/elizabeth-pecoras-sharepoint-blog/you-cannot-update-this-field-because-the-value-youre-trying-to-apply-is-not-valid-or-would-break-a-data-integrity-rule-error
    Best regards.
    Thanks
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How do I get Calendar to suggest name and address from Contacts on my iPhone 5 in iOS 8?

    How do I get Calendar to suggest name and address from Contacts on my iPhone 5 in iOS 8?

    Restore it from your backup.

  • I got an iTunes account years ago with an ID and password...them later got a mobile me and password...now I have an iPad and downloaded iCloud and I can't get my movies and tv shows on iPad because different account name and password from my mobile me.

    I can't get my movies and tv shows on iPad now that I have added iCloud. The problem is that my iTunes account has different name and password from my mobile me account.  Can I change my iTunes account name and password so that they will transfer to my iPad with the mobile me / iCloud account? I need to figure out how to make the two accounts one or iCloud has to be able to accept my iTunes account with years of music and movies.

    Hunter of Sock Monsters thanks...I did follow your advise.  I went to the iforgot site and tried answering the secret questions twice.  I got the "wrong answer", so the next time I asked for an email authentication.  I am still waiting. I don't know what the usual time for waiting normally is. I am still waiting for an email reply from three days ago.  I'm not going to hold my breath.  My ipad is out of warranty but I may have to beg for help from support? I'll wait awhile longer.  Maybe there is another thing someone could come up with.  I appreciate your fast reply Hunter.

  • Somehow my MacBookPro iCloud account has a different name and password from my other devices.  Even my date of birth is listed incorrectly.  I have tried but can't seem to change this info to match up with my other devices.  Can someone help?

    Somehow my MacBookPro iCloud account has a different name and password from my other devices.  Even my date of birth is listed incorrectly.  I have tried but can't seem to change this info to match up with my other devices.  Can someone help?

    Thanks
    I have a PC (Windows 7)
    Not sure when mobile me changed, but it was this weekend that my storage etc. lapsed (I have paid to keep storage with icloud). So i assume this has something to with it stopping.

  • Why can't I delete a user name and password from saved passwords in iOS 7?

    Why can't I delete a user name and password from saved passwords in iOS 7? I found them and they are not anything that I am familiar with? They are from a t-com.de. I have been to Germany in the last month. Not sure if there is any association. Any thoughts? 

    You found them ... where?  Are they in Safari somewhere?
    If so, do Settings > Safari > Clear History and Settings > Safari > Clear Cookies and Data
    If that doesn't clear them (and they are from Safari), try Settings > Safari > Advanced > Website Data and clear that area.

  • Adding caller with name and number from call list to the contact list only inserts the number and not the name

    I recently bought a BlackBerry Z10 and moved my cell service to Rogers to take advantage of the name display service offered by Rogers (Fido also offers this service).
    Due to the number of calls that I receive from first time clients, I wanted the name display service to help me know who was calling. Evidently it is impossible to add clients to my contact list before they call me so I'm constantly seeing numbers that have no name to help me decide if I want to answer the call.
    When I try to add a caller from my call list to my contact list, only the number gets inserted in the new contact. The name needs to be entered manually.
    I understand and realize that not all call display formats are the same and that it's virtually impossible to parse the first and last names from the name portion of the caller id.
    However, I would like to see BlackBerry add the functionality to insert the name portion of the call entry from the caller list to a "Nickname" entry in the contact list just like it adds the number to a "Home", "Mobile", or "Work" entry in the contact list.
    If a user doesn't have a name display service, there would be no change to how their contacts are added because there is no name variable to copy over.
    Can someone from BlackBerry please let me know if this feature can be added to BB10 and when it can be added? For me it's an obvious feature that should just work.
    I am really enjoying my Z10 but I'm feeling let down that something so logical and helpful is not supported out of the box.
    Regards,
    Marc

    Hey ViciousFerret,
    It appears that you are not aware of the fact that both Rogers and Fido offer name AND number display service (although the name display feature is an add-on service) and have been offering it for many years (since 2006). Here is a link to the name display service description of each provider...
    http://www.fido.ca/web/content/manageyourcalls/calldisplay&lang=en
    http://www.rogers.com/business/on/en/smallbusiness/products/wireless/addons/valuepacks/
    As you can see from the link below, Rogers and Fido have been offering this service since 2006.
    http://www.businesswire.com/news/home/20060914005951/en/Teams-HP-Rogers-Wireless-Fido-Succeed-North
    My BlackBerry Z10 shows both the name and number when someone calls (and the caller is not in my contact list).
    All I would like is for the Z10 (and Q10) to support the addition of the name and number from the caller list to my contact list without me having to type the name. As I mentioned in my original post, to avoid the OS having to parse the first name and last name from the name portion of the caller list entry the name could simply be added to the contact list as a "Nickname". If your provider only has number display, nothing would have to be copied from the name variable in the caller list to the contact list.
    I find it difficult to believe that BlackBerry would not be aware of this name display service since it's been around since 2006 with both Rogers and Fido.
    I hope I have clarified the reasons why I would like to have this feature added to BB10 and how it's surprising that this simple feature is not already a part of the BB10 OS.
    Either way, I don't think this is a difficult feature for the BlackBerry team to add. They're just copying a 2nd variable from the caller list to the contact list.
    I'm surprised that Rogers hasn't asked BlackBerry to add this feature to their phones. I think it would be a popular feature for those who receive a high number of calls from first time callers.
    How can I get this feature request to BlackBerry for their consideration?
    Cheers,
    Marc

Maybe you are looking for

  • Payment Authorization Failed error

    Hey, I'm unable to purchase the PS+Lightroom special offer with my card. I've tried 2 different accounts, 3 different browsers (history clear with disk cleanup), 3 different cards (2 debit + 1 credit), 2 different computers .. I'm still unable to pur

  • UWL - open item in new window

    Hi guys! If I click any UWL item I want it to be opened in new window and not in the main portal window. How to achieve this? Thanx for answer! Olian

  • Airserver multicast mDNS problem

    I have WLC 2504 running     7.4.100.0 with a single 1242AG AP single wireless SSID on the WLC an Apple AIRSERVER and an IPAD which should be able to do mirroring to show ipad screen on the pc they have IPs in same subnet and have base connectivity it

  • Reports - Variable Selection, Restriction Issue

    Hi Experts, I have an object (Region) in the variable selection screen, which is displaying South, East, North, West and some more junk value. I want to have only South, East, North and West on the Variable screen of the Analyzer. I have right clicke

  • Error message on opening standalon SWF files.

    hi. When I double click on the any SWF file (from any location of my system), this error message pop up, which say that " Windows cannot find "<< file path>>" ------ but file is goting to play in background. each time when i open SWF files i got the