In many cases, there might be a situation where you want to filter the site data based on the user profiles properties. I had came across the scenario at our client where we had a user profile property – location to associate branch office location to the corporate user profile and later we wanted to filter news information on the intranet MOSS publishing portal based on the logged in user’s location (news content pages based on the page layouts with location site column based on custom field type based on user profile property). In this case, we accessed the user profile data in the code using following-
First step is to populate the user profiles in the SSP with the custom “SiteLocation” property.
Next step is to import the MOSS 2007 assemblies –
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
Last step is to retrieve the user profile property in the custom code –
ServerContext context = ServerContext.GetContext(SPContext.Current.Site);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile userProfile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
string location = userProfile[“SiteLocation”].Value.ToString();
Hope it will be useful.