How can i find user by nickname ? - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

How can i find user by nickname ?

  • How can i find user by nickname ?
  • 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 ?
  • 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
  • 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();
  • 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
  • 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.