1

I have an application page (SP2010) where I have a SPUser object (the current user), now I would like to display this SPUser as an Hyperlink on the apsx, linked to his UserProfilePage (userdisp.aspx) like those links in a normal list (field Author or Editor). Sure I could make a new hyperlink control and use the attributes (?) of the SPUser object to build something that looks like it could be OOTB from SP - but it isn't.

Is there any "best practice way" or "official MS way" to display these information? Perhaps so that the lync status of the User will be shown too?

1 Answer 1

0

Have you tried to use SPFieldUser.GetFieldValueAsHtml method?

Update

You can try use this code, but I'm not sure about details because it from my head and I cannot test it now.

SPUser user = SPContext.Current.Web.CurrentUser;
SPFieldUser userField = SPContext.Current.Web.Fields[SPBuiltInFieldId.AssignedTo] as SPFieldUser;
string userLookup = string.Format("{0};#{1}", user.ID, user.Name);
string link = userField.GetFieldValueAsHtml(userLookup);
4
  • No, this is new too me. Will give it a try, thanks.
    – mr.purzel
    Commented Jul 17, 2014 at 14:31
  • Maybe i don't get it - but this will require a list where I read a field, right? I have no list, I have only a SPUser Object (SPContext.Current.Web.CurrentUser). Or maybe someone have an example too share?
    – mr.purzel
    Commented Jul 17, 2014 at 15:01
  • @mr.purzel, see the update section of my answer.
    – Alexander
    Commented Jul 21, 2014 at 7:26
  • Yes! Thanks, that will do it for me! Didn't check yet if lync status is shown up beside the user name (lync server isn't installed yet on the SP server), but looks good in the html source. Happy!
    – mr.purzel
    Commented Jul 21, 2014 at 8:21

Your Answer

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

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