1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How can i find user by nickname ?

How can i find user by nickname ?

5 posts, 0 answered
  1. Sungyoung
    Sungyoung avatar
    3 posts
    Registered:
    03 Sep 2012
    19 Jun 2012
    Link to this post
    UserProfileManager.GetManager().GetUserProfiles().Where(p => p.NickName == "xxx").SingleOrDefault();

    Is it possible to doing something like this ? and for other custom fields added to basic profile ?
  2. Grace Hallwachs
    Grace Hallwachs avatar
    144 posts
    Registered:
    03 Nov 2014
    22 Jun 2012
    Link to this post
    Hello,

    Yes this is possible. I have included a code snippet retrieving the nickname of the UserProfile.

    //Get the user profile manager
                var pManager = UserProfileManager.GetManager();
                //Retrieve the nickname
                var nickname = "myNickname";
                //Get the nickname of the user profile
                var profile = pManager.GetUserProfiles().OfType<SitefinityProfile>().Where(p => p.Nickname == nickname).FirstOrDefault();


     I have included a link to the documentation which explains how to query some of the user profile information. You can use this as a guide to query information.

    Please let us know if you have any additional questions. Greetings,
    Grace Hallwachs
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Sungyoung
    Sungyoung avatar
    3 posts
    Registered:
    03 Sep 2012
    22 Jun 2012
    Link to this post
    Thanks for your reply.
    I can see the NickName is in the properties list, but other custom fields not.
    it generates compile error.
    How can it be done for those custom field that i added to basic profile

    var profile = pManager.GetUserProfiles().OfType<SitefinityProfile>().Where(p => p.CustomField == "xxx").FirstOrDefault();
  4. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    22 Jun 2012
    Link to this post
    Hi Sungyoung,

    I have answered you in the support ticket.

    All the best,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Sungyoung
    Sungyoung avatar
    3 posts
    Registered:
    03 Sep 2012
    27 Jun 2012
    Link to this post
    var manager = UserManager.GetManager();
    var profileManager = UserProfileManager.GetManager();
    //Get all users
    var usersList = manager.GetUsers();
    //Create an empty list to store the matching users
    var usersMatchList = new List<User>();
    foreach (User myUser in usersList)
    {
        //Load the user profile for each user
        var userProfile = profileManager.GetUserProfile(myUser.Id, typeof(SitefinityProfile).FullName);
       
        if (userProfile.GetValue<String>(customfield) != null)
        {
            if (userProfile.GetValue<String>(customfield).Contains(customvalue))
            {
                //If so, add the user to the list
                usersMatchList.Add(myUser);
            }
        }
    }

    I got the answer. but it's not aplicable.
    Searching value from custom field is not supported.
5 posts, 0 answered