0

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?

0

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 :)

0

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.