Hi
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?
views:
42answers:
2
A:
you do not. The name is not guaranteed to be unique without the domain prefix. If you erally want to show it without, then just remove it - split the string at the "\" and use the second element. There are multiple ways do do that, from the Split method on the string to using IndexOf for the "\" and then substring to extract the reminder.
TomTom
2010-05-11 06:24:34
+1
A:
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.
Sohnee
2010-05-11 06:28:23