{"id":213,"date":"2012-02-13T18:03:54","date_gmt":"2012-02-13T12:33:54","guid":{"rendered":"https:\/\/blog.binarybits.net\/?p=213"},"modified":"2012-02-13T18:03:54","modified_gmt":"2012-02-13T12:33:54","slug":"displaying-current-user-in-sharepoint-master-page","status":"publish","type":"post","link":"https:\/\/blog.binarybits.net\/displaying-current-user-in-sharepoint-master-page\/","title":{"rendered":"Displaying Current User In SharePoint Master Page"},"content":{"rendered":"
One of the requirements while I was working in SharePoint 2010 was displaying the user name in the master page.<\/p>\n
So the following are the 2 pieces of code.<\/p>\n
Add the following code to the body tag inside master page. Make sure the below code is outside of any tag which has the runat=”server” property set.<\/p>\n
<script type=”text\/javascript”>var loginName = “<%= Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name %>”;<\/script><\/p>\n
Now put the following code where ever required.<\/p>\n
<span>Welcome, <script type=”text\/javascript”>document.write(loginName);<\/script><\/span><\/p>\n
<\/p>\n
If you face the following error…check out the link https:\/\/blog.binarybits.net\/?p=207<\/a><\/p>\n An unexpected error has occurred\u00a0<\/p><\/blockquote>\n If you face the following error…check out the link https:\/\/blog.binarybits.net\/?p=215<\/a><\/p>\n Code blocks are not allowed in this file<\/p><\/blockquote>\n