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

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?

share|improve this question

1 Answer 1

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

or

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");
}
else
{
     //Default image
}

var userUrl = profile.PersonalUrl
share|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

 
discard

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

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