Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating user reports

Status
Not open for further replies.

whoodat

IS-IT--Management
Apr 25, 2005
2
US
Can anyone please tell me if there is a way to create a user report that will display all the users within SPS, with fields containing: first name, last name, email address, and phone number...?

Is this possible? If so, can someone please guide me through the steps?

Thanks in advance!
 
I have no experience with SPS, but i do have experience with WSS. An there there is no easy way, but there is a way, again build a webpart :)

The object model has the following properties(and more) for a SPUser
Email
LoginName
Name

but no phonenumber.. So this leads me to believe there is no (easy)way to get the phonenumber...

To list all users you need admin privelidges (or impersonate).

this code is done by hand so it might not be entirely correct:

Code:
//put this in the RenderWebPart
private string text = ""; 
SPSite topsite = new SPSite("[URL unfurl="true"]http://localhost")[/URL]
SPWeb topweb = topsite.OpenWeb()

foreach (SPUser user in topweb.SiteUsers)
{
   text += user.Email;
   text += user.Name;
   text += user.LoginName;
   text += "<br>";
}
if (topweb.GetSubwebsForCurrentUser().Count > 0){
GoTroughSubsites(topweb);
}
output.Write(text);
//End RenderWebPart


//other methode
private void GoTroughSubsites(SPWeb Web){
   
foreach (SPWeb MyWeb in Web.GetSubwebsForCurrentUser())
   {
      foreach (SPUser user in MyWeb.SiteUsers)
      {
         text += user.Email;
         text += user.Name;
         text += user.LoginName;
         text += "<br>";
      }
      if (MyWeb.GetSubwebsForCurrentUser().Count > 0){
	 GoTroughSubsites(MyWeb);
      }
   }
}
//end other methode

Instead of using text += consider using StringBuilder text; (using System.Text;)
and text.append("text here"); (to write then use output.Write(text.ToString());)
This is much faster!!! - i once had my code go from 30 sec to less than 1 (0.8)sec.

Let me know how it goes!
 
hi thanks for the fast respond! This looks great, i'll let you know how it goes.

Thanks again! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top