I have one sharepoint application, in this i have to show the current user, i used SPContext.Current.Web.CurrentUser.LoginName
. then it returns XXXXXX\abida. But i want only the username like abida. How to achieve this requirement?
Note that we have to escape the slash...
string loginName = SPContext.Current.Web.CurrentUser.LoginName;
string[] loginNameParts = loginName.Split('\\');
string loginNameWithoutDomain = nameParts[1];
I presume you are doing this in order to use the name-only for some reason and that you aren't relying on the user name being unique in its own right. You could have DOMAIN1\BobSmith and DOMAIN2\BobSmith - so if you were using "BobSmith" as a unique user name, you could come unstuck.