Search This Blog

Tuesday, January 6, 2009

Reading user profiles thru code

Here is a code snippet for reading the user profiles:

using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
...
...
...

UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(HttpContext.Current));
foreach (UserProfile profile in profileManager)
{
/* if we know the field name this may help us to get the value directly instead of using the following loop. Have not tried running the line below so please... */
//string empName = profile["PreferredName"][0] as string;

// The following for loop is used for displaying all the Field Names for profile (and
// can be used for fetching or displaying values also
foreach (KeyValuePair val in profile)
{
System.Diagnostics.Debug.WriteLine("Key =" + val.Key);
}
}

No comments: