/// <summary> /// Get the localized label of User Profile Properties /// Option 1 => Get the specific property to find the label (much better performance) /// </summary> /// <param name="userProfilePropertyName"></param> /// <reference> /// 1. http://nikpatel.net/2013/12/26/code-snippet-programmatically-retrieve-localized-user-profile-properties-label/ /// </reference> /// <returns></returns> public string getLocalizedUserProfilePropertiesLabel(string userProfilePropertyName, SPWeb currentWeb) { string localizedLabel = string.Empty; try { //Get the handle of User Profile Service Application for current site (web application) SPSite site = SPContext.Current.Site; SPServiceContext context = SPServiceContext.GetContext(site); UserProfileConfigManager upcm = new UserProfileConfigManager(context); //Access the User Profile Property manager core properties ProfilePropertyManager ppm = upcm.ProfilePropertyManager; CorePropertyManager cpm = ppm.GetCoreProperties(); //Get the core property for user profile property and get the localized value CoreProperty cp = cpm.GetPropertyByName(userProfilePropertyName); if (cp != null) { localizedLabel = cp.DisplayNameLocalized[System.Globalization.CultureInfo.CurrentUICulture.LCID]; } } catch (Exception err) { LogErrorHelper objErr = new LogErrorHelper(LIST_SETTING_NAME, currentWeb); objErr.logSysErrorEmail(APP_NAME, err, "Error at getLocalizedUserProfilePropertiesLabel function"); objErr = null; SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, err.Message.ToString(), err.StackTrace); return(string.Empty); } return(localizedLabel); }
private CoreProperty EnsureCoreProperty( SPSite site, UserProfilePropertyInfo userProfilePropertyInfo, CorePropertyManager userProfileCoreProperties) { // If property is null, create it. Else, update it var property = userProfileCoreProperties.GetPropertyByName(userProfilePropertyInfo.Name); if (property == null) { this.logger.Info("Creating user profile property '{0}'", userProfilePropertyInfo.Name); // Create property (false here means it's not a section) property = userProfileCoreProperties.Create(false); property.Name = userProfilePropertyInfo.Name; property.Type = userProfilePropertyInfo.PropertyDataType; property.Length = userProfilePropertyInfo.Length; property.IsMultivalued = userProfilePropertyInfo.IsMultivalued; } else { this.logger.Info("Updating user profile property '{0}'", userProfilePropertyInfo.Name); } property.DisplayName = userProfilePropertyInfo.DisplayName; property.Description = userProfilePropertyInfo.Description; property.IsAlias = userProfilePropertyInfo.IsAlias; property.IsSearchable = userProfilePropertyInfo.IsSearchable; // Setup localized display name if (userProfilePropertyInfo.DisplayNameLocalized.Count > 0) { foreach (var displayName in userProfilePropertyInfo.DisplayNameLocalized) { property.DisplayNameLocalized[displayName.Key] = displayName.Value; } } // Setup localized description if (userProfilePropertyInfo.DescriptionLocalized.Count > 0) { foreach (var description in userProfilePropertyInfo.DescriptionLocalized) { property.DescriptionLocalized[description.Key] = description.Value; } } // Setup taxonomy mappings if configured if (userProfilePropertyInfo.TermSetInfo != null) { var taxonomyCache = this.siteTaxonomyCacheManager.GetSiteTaxonomyCache(site, null, this.taxonomyHelper); var termStore = userProfilePropertyInfo.TermSetInfo.ResolveParentTermStore(taxonomyCache.TaxonomySession); property.TermSet = termStore.GetTermSet(userProfilePropertyInfo.TermSetInfo.Id); } property.Commit(); return(property); }
private CoreProperty EnsureCoreProperty( SPSite site, UserProfilePropertyInfo userProfilePropertyInfo, CorePropertyManager userProfileCoreProperties) { // If property is null, create it. Else, update it var property = userProfileCoreProperties.GetPropertyByName(userProfilePropertyInfo.Name); if (property == null) { this.logger.Info("Creating user profile property '{0}'", userProfilePropertyInfo.Name); // Create property (false here means it's not a section) property = userProfileCoreProperties.Create(false); property.Name = userProfilePropertyInfo.Name; property.Type = userProfilePropertyInfo.PropertyDataType; property.Length = userProfilePropertyInfo.Length; property.IsMultivalued = userProfilePropertyInfo.IsMultivalued; } else { this.logger.Info("Updating user profile property '{0}'", userProfilePropertyInfo.Name); } property.DisplayName = userProfilePropertyInfo.DisplayName; property.Description = userProfilePropertyInfo.Description; property.IsAlias = userProfilePropertyInfo.IsAlias; property.IsSearchable = userProfilePropertyInfo.IsSearchable; // Setup localized display name if (userProfilePropertyInfo.DisplayNameLocalized.Count > 0) { foreach (var displayName in userProfilePropertyInfo.DisplayNameLocalized) { property.DisplayNameLocalized[displayName.Key] = displayName.Value; } } // Setup localized description if (userProfilePropertyInfo.DescriptionLocalized.Count > 0) { foreach (var description in userProfilePropertyInfo.DescriptionLocalized) { property.DescriptionLocalized[description.Key] = description.Value; } } // Setup taxonomy mappings if configured if (userProfilePropertyInfo.TermSetInfo != null) { var taxonomyCache = this.siteTaxonomyCacheManager.GetSiteTaxonomyCache(site, null, this.taxonomyHelper); var termStore = userProfilePropertyInfo.TermSetInfo.ResolveParentTermStore(taxonomyCache.TaxonomySession); property.TermSet = termStore.GetTermSet(userProfilePropertyInfo.TermSetInfo.Id); } property.Commit(); return property; }