I am using following code in masterpage to print current user

welcome, <%= Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name%>

My output is as follows

welcome, Smith, Rick 

where last name=Smith and first name=Rick

but I need as follows

welcome, Rick Smith

How can I do that?


Try the following in server tags:

<%= Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name.Contains(" ") ? string.Format("{0} {1}", Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name.Split(' ')[1], Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name.Split(' ')[0]) : Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name %>

It seems kind of big but should do the job :)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.