How to get Display Name from login Name in SharePoint 2013

Display Name from login Name  in SharePoint 2013:-

In this post, You will get to readDisplay Name from login Name using SharePoint 2013.User display name is different from login name in an active directory.

 string PWAPath = SPContext.Current.Web.Url;
        public string GetUserName(string LoginName)
        {
            string Name = string.Empty;
            using (SPSite sSite = new SPSite(PWAPath))
            {
                using (SPWeb sWeb = sSite.OpenWeb())
                {
                    SPUserCollection Users = sWeb.AllUsers;
                    foreach (SPUser user in Users)
                    {
                        if (user.LoginName.ToUpper() == LoginName.ToUpper())
                        {
                            Name = user.Name.ToString();
                            break;
                        }
                    }
                }
            }
            return Name;
        }

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!