//This method runs when the button is clicked you should use the references using Microsoft.Office.Server; using Microsoft.Office.Server.UserProfiles; void runQueryButton_Click(object sender, EventArgs e) { //Get the My Sites site collection, ensuring proper disposal using (SPSite mySitesCollection = new SPSite("http://sp/my")) { //Get the user profile manager SPServiceContext context = SPServiceContext.GetContext(mySitesCollection); UserProfileManager profileManager = new UserProfileManager(context); //How many user profiles are there? resultsLabel.Text = "There are " + profileManager.Count + " user profiles.<br />"; //Loop through all the user profiles foreach (UserProfile currentProfile in profileManager) { //There is always a display name resultsLabel.Text += "User: " + currentProfile.DisplayName + "<br />"; //Be careful to avoid null errors if (currentProfile["Department"].Value != null) { //There is a department listed so display it resultsLabel.Text += "Department: " + currentProfile["Department"].Value.ToString() + "<br /><br />"; } else { resultsLabel.Text += "Department: None<br /><br />"; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)