Welcome to MSDN Blogs Sign in | Join | Help

Pranab Paul's Blog - SharePoint 2007 (MOSS/WSS 3.0) Development Tips

------------------------------------------Web Parts, Workflow, InfoPath Form Services, Features, Site Definition, Event Receivers, Excel Services, Business Data Catalog (BDC), Search

News

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

{

    [Guid("e36b58a7-fbe9-4ecf-b545-831929545ebf")]

    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.

            EnsureChildControls();

            writer.Write(output);

        }

 

        protected override void CreateChildControls()

        {

            try

            {

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

                {

                    ServerContext context =

                        ServerContext.GetContext(site);

                    UserProfileManager profileManager = new

                        UserProfileManager(context);

                    foreach (UserProfile profile in profileManager)

                    {

                        //Console.WriteLine(profile[PropertyConstants.AccountName]);

                        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:

 

http://edinkapic.blogspot.com/2007/08/enumerating-user-profiles.html

Posted: Friday, September 14, 2007 8:09 PM by pranab

Comments

SharePoint, SharePoint and stuff said:

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

# September 17, 2007 5:34 AM

Sharath said:

Pranab,

 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 ?

-Thanks

# October 12, 2007 2:54 PM

Sean Nguyen said:

Hi,

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

# December 14, 2007 11:33 AM

snowcounty said:

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

# March 9, 2008 7:48 PM

vishnu rana said:

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.

Thanks,

Vishnu Rana

India

# September 16, 2008 1:43 AM

nitingupta said:

Hi Vishnu,

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

Thanks,

Nitin Gupta

# September 17, 2008 7:15 AM

geets said:

Hello

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

thanx a lot

# October 15, 2008 5:26 AM

Saurabh Kumar Singh said:

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".

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

Thank you,

Saurabh Kumar Singh

# May 15, 2009 4:45 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker