Show random user in webpart

Hi

I'm developing a team site for soccer team. I would like to show a random player (member of the players group) in a webpart on the startpage. Anyone with a sample how to handle this.

Regards

Peter

[232 byte] By [PeterSonander] at [2008-1-1]
# 1

Are the "players" users in the site, or is this just a list of players?

If it's a list, I suggest the following psuedo code:

  1. Connect to the list (see my common and simple tasks - http://www.sharepoint-tips.com/2006/08/common-and-simple-coding-tasks-in.html)
  2. Get the number of items in the list (List.Items.Count)
  3. Generate a random number up to the count, and get the list item in that index.
  4. Get the properties of the list item (again, see my common coding tasks) and display them on the page.

I assume you know how to write a webpart. If not, I suggest you read about this http://blogs.tamtam.nl/mart/CreateASharePoint2007WebpartStepByStep.aspx

IshaiSagi at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 2

Thanx

They are users in the site, do you know if it possible to handle that instead?

Otherwise thanks for the sample

PeterSonander at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 3

Peter,

In my blog (link below) you will find (search for "common coding tasks") how to connect to the SPWeb object using code.

After doing that, you have access (using the .Users property of the SPWeb object) to the list of users that:

  • have access to the site
  • and have been added explicitly (not as part of a group)
  • or have been added through a group and have visited the site.

You can then implement the same logic I mentioned earlier with randomly selecting one of them (use the SPUser object to get to their properties as are tracked in the site)

IshaiSagi at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 4

Thanks

I'll try that.

Peter

PeterSonander at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...

SharePoint Products and Technologies

Site Classified