I have a Custom WebPart which gets credentials from the site into a GridView-Table. The result (user and credential) is shown as strings. I want to create a Hyperlink to the users e.g. mysite, instead using strings. Is this possible?


There are built in web-parts for this, but I always feel they aren't quite right.

So what you need to access is:

SPWeb > SPGroupCollection > ForEach SPGroup > ForEach SPGroup.Users > SPUser.OwnedGroups

Then display out your tree like:

Users > Groups


Groups > Users

The code for getting the properties is:

SPServiceContext serviceContext = SPServiceContext.GetContext(SPSite);
UserProfileManager manager = new UserProfileManager(serviceContext);
UserProfile profile = manager.GetUserProfile(oUser.ToString());
ProfileValueCollectionBase FirstName = profile.GetProfileValueCollection("FirstName");
ProfileValueCollectionBase LastName = profile.GetProfileValueCollection("LastName");

if (profile["PictureURL"].Value != null)
    ProfileValueCollectionBase baseVal = profile.GetProfileValueCollection("PictureURL");
     //Default image

var userUrl = profile.PersonalUrl
| improve this answer | |
  • Hi Hugh, thanks for your answer. I have the URL as a string in a Datatable and want to create a Hyperlink out of the URL. I tried to build a html in the datatable. But the datatable does not accept html, only Content :) Do you know how I can make a string-url in a datatable(gridview) into a Hyperlink? – grekko Nov 28 '12 at 8:49
  • From code behind, you would have to override the renderer. Or have it print out in some sort of pseudo tags that a javascript function updates on page? The two things that instantly come to mind for fixing that. – Hugh Wood Nov 28 '12 at 8:51

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.