Posts Tagged ‘programming’

SharePoint 2010 : Retrieve User Profile Properties Programmatically

March 17, 2012 Leave a comment

To display the user profile properties that exist on the server Also add references to the following in your Microsoft Visual Studio project:

  • Microsoft.Office.Server
  • Microsoft.Office.Server.UserProfiles
  • Microsoft.SharePoint
  • System.Webhere, in below example, we need to check if ¬†propertyName exits in user profile properties store or not.

    private bool CheckIFPropertyExist(string propertyName, string siteName)
    using (SPSite currentSite = new SPSite(siteName))
    SPServiceContext context = SPServiceContext.GetContext(currentSite);
    ProfileSubtypeManager profileMgr = ProfileSubtypeManager.Get(context);
    ProfileSubtype profileSubType = profileMgr.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
    ProfileSubtypePropertyManager profilePropertyMgr = profileSubType.Properties;

    foreach (ProfileSubtypeProperty profileSubtypeProperty in profilePropertyMgr.PropertiesWithSection)
    if (profileSubtypeProperty.Name != propertyName)
    return false;
    return true;