/ Published in: C#
Returns the username (domain\username) of the user that is currently logged in sharepoint. Can be used inside features / custom pages
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/// <summary> /// Returns the username of the currently logged in user /// </summary> private string CurrentUserName() { string userName = "NA"; SPContext currentContext; try { //Getting the current context currentContext = SPContext.Current; } catch (InvalidOperationException) { currentContext = null; } if (currentContext != null && currentContext.Web.CurrentUser != null) { userName = SPContext.Current.Web.CurrentUser.LoginName; } return userName; }