Get full name by log in name in sharepoint 2010
Is there an easy way to retrieve fullname e.g "John Smith" from its login name "j.smith" in sharepoint? Ive been ages looking for that code.
I have this code:
string strName = SPUtility.GetAccountName("j.smith");
Where strName should be my fullname and "j.smith" is my login name. I dont think its correct..any advice from sharepoint masters out there?
If the user whose full name needs to be fetched is already added to the site or it is Ok that the user be added to the site you can use :
Alternatively you can use User profile service and get the full name of the user from his user profile if the user is not added to the site and you do not want to add that user to the site.
SPServiceContext context = SPServiceContext.GetContext(site); UserProfileManager upm = new UserProfileManager(context); UserProfile profile = upm.GetUserProfile(@"zsdev\ia"); Console.WriteLine(profile.DisplayName);
If you have a current SPWeb you can use web.EnsureUser(loginName).Name.