I had plans to extend our custom MOSS application with some deeper personalization. Specifically, certain forms elements would appear/disappear for you based on your department and your position in the org chart. In additional, certain dropdowns would be filtered for your team/peers/shared interests. Notice that this is for data entry and workflow acceleration so this isn’t data that needs to be secured. So the two necessary pieces are
1. Figuring out the current user’s profile
The dll that needs to be included is Microsoft.Office.Portal (Microsoft.SharePoint.Portal.UserProfiles is deprecated). The class is UserProfileManager. This will let you quickly get the current user’s profile for display or editing. The UserProfileManager class is enumerable so you can walk through all of the user profiles. But that doesn’t seem to be the most performant method of building groups based on profile information.
2. Searching across all user profiles
If you are looking across all user profiles as opposed to just the current user, you will want to use the search functions. The easiest way to do this is to restrict your search to the "People Scope". The code snippet below will return all users in the IT Department. You will notice that we defined the scope to be people in the FullTextSQLQuery (make sure your content source is setup for this).
FullTextSqlQuery q = new FullTextSqlQuery(ServerContext.Current);
q.ResultTypes = ResultType.RelevantResults;
q.QueryText = "SELECT UserName, Email, PreferredName FROM SCOPE() WHERE \"scope\" = 'People' AND Department = 'IT'";
ResultTableCollection tables = q.Execute();
ResultTable results = tables[ResultType.RelevantResults];