Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

Are you doing this in code?

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

share|improve this answer
    
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 '11 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 '11 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 '11 at 15:39
add comment

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);     
});
</script>

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.