none
User Info Popup

    Question

  • Hi,

    I wonder if it is possible to create a user info popup on a custom page like the popup that we can find in the People and Groups sections of a site's Permission page.
    If you hold your mouse on a user's name a popup appears which contains information about that person.

    Is there a control or piece of code for this or do i have to create one myself?

    Thanks in advance.

    Wednesday, June 19, 2013 11:19 AM

Answers

  • It's possible to create one (I've done so), but I'm not sure of easy way of achieving this OOTB.

    To create one, I created an application page that takes a username as a parameter, then returns information from the User Profile Service. The application page gets displayed in a Modal Dialog (i.e. when doing a people search, you click on the person, this application page is displayed (in place of the mysite page)).

    Example code for accessing the User Profile (from a webpart):
    Note: You need to add a reference to Microsoft.Office.Server.UserProfiles.dll

    [ToolboxItemAttribute(false)]
    public class People : WebPart
    {
        private Label details;
        protected override void CreateChildControls()
        {
            details = new Label();
            Controls.Add(details);
        }
    
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            try
            {
                GetUserDetails(SPContext.Current.Web.CurrentUser.LoginName);
            }
            catch (Exception exception)
            {
                details.Text = exception.Message;
            }
        }
    
        private void GetUserDetails(String samAccount)
        {
            SPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Web.Site);
            UserProfileManager upm = new UserProfileManager(serviceContext);
            UserProfile up = upm.GetUserProfile(samAccount);
            String firstName = up.GetProfileValueCollection("FirstName").Value == null ? String.Empty : (String)up.GetProfileValueCollection("FirstName").Value;
            String lastName = up.GetProfileValueCollection("LastName").Value == null ? String.Empty : (String)up.GetProfileValueCollection("LastName").Value;
            UserProfileValueCollection pictureUrl = up["PictureURL"];
            String jobTitle = up.GetProfileValueCollection("SPS-JobTitle").Value == null ? String.Empty : (String)up.GetProfileValueCollection("SPS-JobTitle").Value;
            String department = up.GetProfileValueCollection("Department").Value == null ? String.Empty : (String)up.GetProfileValueCollection("Department").Value;
            var office = (String)GetProperty(up, "SPS-Location") ?? String.Empty;
            var homePhone = GetProperty(up, "HomePhone") ?? String.Empty;
            var personalMobile = GetProperty(up, "personalMobile") ?? String.Empty;
            var workMobile = GetProperty(up, "CellPhone") ?? String.Empty;
            Boolean askMeAboutExists = DoesPropertyExists(up, "SPS-Responsibility");
            var aboutMe = GetProperty(up, "AboutMe") ?? String.Empty; //up["AboutMe"];
            StringBuilder userProperties = new StringBuilder();
    
            userProperties.Append(String.Format("<div><span>First Name:</span><span>{0}</span></div>", firstName));
            userProperties.Append(String.Format("<div><span>Last Name:</span><span>{0}</span></div>", lastName));
            if (!String.IsNullOrEmpty((string)aboutMe))
            {
                userProperties.Append(String.Format("<div><span>About Me:</span><span>{0}</span></div>", aboutMe));
            }
    
            if (askMeAboutExists)
            {
                UserProfileValueCollection askMeAbout = up["SPS-Responsibility"];
                if (askMeAbout != null)
                {
                    if (askMeAbout.Count > 0)
                    {
                        var s = new StringBuilder();
                        foreach (var i in askMeAbout)
                        {
                            if (i != null)
                            {
                                s.Append(String.Format("{0}; ", i));
                            }
                        }
                        userProperties.Append(String.Format("<div><span>Ask Me About:</span><span>{0}</span></div>", s));
                    }
                }
            }
            details.Text = userProperties.ToString();
        }
    
        private static bool DoesPropertyExists(UserProfile userProfile, String property)
        {
            foreach (KeyValuePair<String, UserProfileValueCollection> value in userProfile)
            {
                var key = value.Key;
                if (value.Key.ToLower().Equals(property.ToLower()))
                {
                    var valType = value.Value.GetType();
                    return true;
                }
            }
            return false;
        }
    
        private static object GetProperty(UserProfile userProfile, String property)
        {
            foreach (KeyValuePair<String, UserProfileValueCollection> keyValuePair in userProfile)
            {
                if (keyValuePair.Key.ToLower().Equals(property.ToLower()))
                {
                    return keyValuePair.Value.Value;
                }
            }
            return null;
        }
    }


    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    I just added a webpart to the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here: Upload and Crop User Profile Photos

    Wednesday, June 19, 2013 12:30 PM
  • Hi M. van Heijningen,

    The functionality you're talking about (I misunderstood your initial question) is provided via an ActiveX control supplied by Lync (or Office Communicator) integration.

    There's some information on it here: Lync 2010 Integration (http://technet.microsoft.com/en-us/library/gg398806(v=ocs.14).aspx)

    And a Microsoft blog on how to create the functionality in a page: How to add presence/pawn to SharePoint contacts list (http://blogs.msdn.com/b/modonovan/archive/2005/05/11/416376.aspx)

    Hope that helps!


    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    I just added a webpart to the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here: Upload and Crop User Profile Photos

    Tuesday, June 25, 2013 11:59 AM

All replies

  • It's possible to create one (I've done so), but I'm not sure of easy way of achieving this OOTB.

    To create one, I created an application page that takes a username as a parameter, then returns information from the User Profile Service. The application page gets displayed in a Modal Dialog (i.e. when doing a people search, you click on the person, this application page is displayed (in place of the mysite page)).

    Example code for accessing the User Profile (from a webpart):
    Note: You need to add a reference to Microsoft.Office.Server.UserProfiles.dll

    [ToolboxItemAttribute(false)]
    public class People : WebPart
    {
        private Label details;
        protected override void CreateChildControls()
        {
            details = new Label();
            Controls.Add(details);
        }
    
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            try
            {
                GetUserDetails(SPContext.Current.Web.CurrentUser.LoginName);
            }
            catch (Exception exception)
            {
                details.Text = exception.Message;
            }
        }
    
        private void GetUserDetails(String samAccount)
        {
            SPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Web.Site);
            UserProfileManager upm = new UserProfileManager(serviceContext);
            UserProfile up = upm.GetUserProfile(samAccount);
            String firstName = up.GetProfileValueCollection("FirstName").Value == null ? String.Empty : (String)up.GetProfileValueCollection("FirstName").Value;
            String lastName = up.GetProfileValueCollection("LastName").Value == null ? String.Empty : (String)up.GetProfileValueCollection("LastName").Value;
            UserProfileValueCollection pictureUrl = up["PictureURL"];
            String jobTitle = up.GetProfileValueCollection("SPS-JobTitle").Value == null ? String.Empty : (String)up.GetProfileValueCollection("SPS-JobTitle").Value;
            String department = up.GetProfileValueCollection("Department").Value == null ? String.Empty : (String)up.GetProfileValueCollection("Department").Value;
            var office = (String)GetProperty(up, "SPS-Location") ?? String.Empty;
            var homePhone = GetProperty(up, "HomePhone") ?? String.Empty;
            var personalMobile = GetProperty(up, "personalMobile") ?? String.Empty;
            var workMobile = GetProperty(up, "CellPhone") ?? String.Empty;
            Boolean askMeAboutExists = DoesPropertyExists(up, "SPS-Responsibility");
            var aboutMe = GetProperty(up, "AboutMe") ?? String.Empty; //up["AboutMe"];
            StringBuilder userProperties = new StringBuilder();
    
            userProperties.Append(String.Format("<div><span>First Name:</span><span>{0}</span></div>", firstName));
            userProperties.Append(String.Format("<div><span>Last Name:</span><span>{0}</span></div>", lastName));
            if (!String.IsNullOrEmpty((string)aboutMe))
            {
                userProperties.Append(String.Format("<div><span>About Me:</span><span>{0}</span></div>", aboutMe));
            }
    
            if (askMeAboutExists)
            {
                UserProfileValueCollection askMeAbout = up["SPS-Responsibility"];
                if (askMeAbout != null)
                {
                    if (askMeAbout.Count > 0)
                    {
                        var s = new StringBuilder();
                        foreach (var i in askMeAbout)
                        {
                            if (i != null)
                            {
                                s.Append(String.Format("{0}; ", i));
                            }
                        }
                        userProperties.Append(String.Format("<div><span>Ask Me About:</span><span>{0}</span></div>", s));
                    }
                }
            }
            details.Text = userProperties.ToString();
        }
    
        private static bool DoesPropertyExists(UserProfile userProfile, String property)
        {
            foreach (KeyValuePair<String, UserProfileValueCollection> value in userProfile)
            {
                var key = value.Key;
                if (value.Key.ToLower().Equals(property.ToLower()))
                {
                    var valType = value.Value.GetType();
                    return true;
                }
            }
            return false;
        }
    
        private static object GetProperty(UserProfile userProfile, String property)
        {
            foreach (KeyValuePair<String, UserProfileValueCollection> keyValuePair in userProfile)
            {
                if (keyValuePair.Key.ToLower().Equals(property.ToLower()))
                {
                    return keyValuePair.Value.Value;
                }
            }
            return null;
        }
    }


    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    I just added a webpart to the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here: Upload and Crop User Profile Photos

    Wednesday, June 19, 2013 12:30 PM
  • Hi Matthew,

    Thanks for your reply but i meant something more like this:

    is you put your mouse on somebody's name in sharepoint or even in your outlook a mouseover menu will appear.

    Is there any default control for that?

    Monday, June 24, 2013 11:20 AM
  • Hi,

    I dont think there is any default control for that, one way would be to show the person.aspx page if you have configured the mysite. Just pass the account name of the user as query string  on mouse over and open the person.aspx page in a popup.

    Regards,

    Soumya Rao

    Tuesday, June 25, 2013 9:37 AM
  • Hi M. van Heijningen,

    The functionality you're talking about (I misunderstood your initial question) is provided via an ActiveX control supplied by Lync (or Office Communicator) integration.

    There's some information on it here: Lync 2010 Integration (http://technet.microsoft.com/en-us/library/gg398806(v=ocs.14).aspx)

    And a Microsoft blog on how to create the functionality in a page: How to add presence/pawn to SharePoint contacts list (http://blogs.msdn.com/b/modonovan/archive/2005/05/11/416376.aspx)

    Hope that helps!


    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    I just added a webpart to the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here: Upload and Crop User Profile Photos

    Tuesday, June 25, 2013 11:59 AM
  • Thanks for the feedback.

    Im going to read it and see if i can apply it in my solution :)

    Friday, June 28, 2013 9:17 AM