A SharePoint 2007 (MOSS/WSS) WebPart showing the list of users of a site with a link to corresponding MySite

Add a reference of Microsoft.Office.Server.dll. Here is the Code:

using System;

using System.Runtime.InteropServices;

using System.Web.UI;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Serialization;


using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using Microsoft.SharePoint.WebPartPages;

using Microsoft.Office.Server.Administration;

using Microsoft.Office.Server.UserProfiles;

using Microsoft.Office.Server;

using System.IO;


namespace UserProfileWP



    public class UserProfileWP : System.Web.UI.WebControls.WebParts.WebPart


        string output = "<table border=\"0\">";

        protected override void Render(HtmlTextWriter writer)


            // TODO: add custom rendering code here.





        protected override void CreateChildControls()




                using (SPSite site = new SPSite("<your site url>"))


                    ServerContext context =


                    UserProfileManager profileManager = new


                    foreach (UserProfile profile in profileManager)



                        output += "<tr><td><a href=\"" + profile.PublicUrl.AbsoluteUri + "\"/>" + profile[PropertyConstants.AccountName] + "</a></td></tr>";


                    output += "</table>";



            catch (Exception ex)


                output += "<tr><td>" + ex.ToString() + "</td></tr></table>";






Addition: While using this Web Part you may find errors saying "Access Denied: Only an administrator may enumerate through all user profiles" for users other than Administrator. If you want to remove this, you have to set the User Permission using Shared Services. A nice post related to this:



Comments (9)

  1. Hi,

    I am just associating a custom Event handler feature with SharePoint "User Information" list, for creating a copy of newly added user in another sharepoint custom list with the help of "ItemAdded" event handler, which will maintain user

    profile but it doesn’t seems to fire ItemAdding event with "User Information" list.

    I have read this article: "http://msdn.microsoft.com/en-us/library/aa979520.aspx&quot;.

    So, can you please suggest me that how can i handle events for "User Information" list?

    Thank you,

    Saurabh Kumar Singh

  2. geets says:


    this code doesn’t work on my vs. can you upload a ready webpart? i need it very much

    thanx a lot

  3. nitingupta says:

    Hi Vishnu,

    I am also looking for these answers. If i get something, i will reply.


    Nitin Gupta

  4. vishnur says:

    Hi Pranab,

    I am new to sharepoint and I have few questions as follows:

    1. How do i create a web Part for Organizational Hierarchy list in WSS 3.0 specially, as SSP and Profile management does not exists in WSS 3.0

    2. what are the pros & cons of ‘User Information List’ when used.


    Vishnu Rana


  5. snowcounty says:

    Accessing the User Profile Store Using the Object Model: http://msdn2.microsoft.com/en-us/library/ms574336

  6. Sean Nguyen says:


    Sharepoint 2007 is very interesting to discover,

    Well I’m pretty new with sharepoint, but I do have the desire to learn and create different things with sharepoint.I have couple of questions and I need help

    first of all how can I create a web Part for Organizational Hierarchy list, with out any links to Mysite, mean I can add a webpart to any page I want.

    Secondly how can I build a webpart or any webpart out there that allow me to do just like wikipedia?

    thank you very much for your help

  7. Sharath says:


     Can i filter subset of users using UserProfileManager ?

     I want to get a list of all the users based on their location instead of looping through all the profiles. Is there any way to apply SPQuery ?


  8. Schritt-für-Schritt zur eigenen Web Content Management Site und diese dann mit optimierter Performance

Skip to main content