Get NT User ID in SharePoint

What's the easiest way to get the NT-ID of a user in a C # application? I will probably need to get it with just the username, or perhaps an email address.

+1


source to share


2 answers


Inside SharePoint, you can retrieve the user's Active Directory information (including display name and email address) using SPUtility.ResolveWindowsPrincipal:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.resolvewindowsprincipal.aspx

For example:



SPPrincipalInfo pi = SPUtility.ResolveWindowsPrincipal(SPContext.Current.Site.WebApplication, "MYDOMAIN\\myusername", SPPrincipalType.All, false);

      

Outside of SharePoint, you want to look at the System.DirectoryServices namespace.

+1


source


In most cases, you can get it from the current network, for example:



string login = SPContext.Current.Web.CurrentUser.LoginName
string mail = SPContext.Current.Web.CurrentUser.Email

      

+3


source







All Articles