How to get login name from Display Name in SharePoint 2013

login name from Display Name in SharePoint 2013:-

In this post, I explain to get login name from Display Name in SharePoint 2013. Login name is different from display name

using Microsoft.SharePoint;

string PWAPath = SPContext.Current.Web.Url;

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

 

 


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 !!