Could you please help me how to add the e-mail address of the logged user into a form field? From the user profile, the email address is stored there, I need to extract and dislplay the e-mail address in a form field. Something similar to the name of the user that is displayed next to the "Welcome" message.

I found something similar and i tested it by pasting it in the default.master, but i got an error that a block cant be used in that file.

<script type="text/c#" language="C#" runat="server">
protected void Page_Load(Object sender, EventArgs e)
{    LabelUserName.Text = Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name;}</script>

<asp:Label ID="LabelUserName" runat="server"></asp:Label>

Thanks in advance.

2 Answers 2


Are you doing this in code?

SPContext.Current.Web.CurrentUser.Email will return the email address of the currently logged on user.

  • Looks nice, can you however gime a litle more information? Im new with the SP, and some things are not really clear to me.
    – user1360
    Feb 4, 2011 at 13:19
  • Please check the edit, but i got an error message that i can't use a block in default.master
    – user1360
    Feb 4, 2011 at 13:43
  • In what context are you doing this in? ie: Which form is this? Creating a new item? If so, you can use the suggestion on this thread to use SPServices, you'll need to put the code snippet below into a content editor web part (which will need to be entered into a customised New Item form done in SharePoint Designer), and put the SPServices library somewhere on your site. Your content editor web part will probably also have to reference the SPServices library. Have a good round for SPServices and examples to get you started.
    – James Love
    Feb 4, 2011 at 15:39

Marc Anderson has a jQuery library called SPServices that will allow you to retrieve it easily. You add references to jquery and spservices on your page and you'd do this:

<script type="text/javascript">
$(document).ready(function() {
    var User = $().SPServices.SPGetCurrentUser({
        fieldName: "EMail",
        debug: false
    $("textarea[title='People Picker']").val(User);
    $("div[title='People Picker']").text(User);     

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.