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'm developing a visual webpart (TreeView). If I click on a node (folder), it gives me the credentials of the folder. Now, the values are all appearing in a label.

How can I return the users and groups not as string, but as a "SPUser-Hyperlink" like you can see in lists, when you create a coloumn and select the field "persons and groups".

share|improve this question
add comment

1 Answer 1

String UserName= “UserNameGoesHere”; 

SPUser oUser= SPWeb.EnsureUser(UserName); 
treenode.SelectedNode.Nodes.Add(oUser.Name);

Where “UserNameGoesHere” you can change that to a varible as you loop through each string.

or from msdn

SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPUser oUser = oWebsite.AllUsers["User_Name"];

    treenode.SelectedNode.Nodes.Add(oUser.Name);

}

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.aspx

You would need to iterate through all the names by having in the using a while or forloop to go through the whole list!

hope this helps :)

share|improve this answer
add comment

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.