private static ProfileSubtypeProperty EnsureProfileSubtypeProperty( ProfileTypeProperty profileTypeProperty, UserProfilePropertyInfo userProfilePropertyInfo, ProfileSubtypePropertyManager profileSubtypePropertyManager) { var profileSubtypeProperty = profileSubtypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name); if (profileSubtypeProperty == null) { profileSubtypeProperty = profileSubtypePropertyManager.Create(profileTypeProperty); profileSubtypeProperty.IsUserEditable = userProfilePropertyInfo.IsUserEditable; if (userProfilePropertyInfo.DefaultPrivacy.HasValue) { profileSubtypeProperty.DefaultPrivacy = userProfilePropertyInfo.DefaultPrivacy.Value; } profileSubtypePropertyManager.Add(profileSubtypeProperty); } else { profileSubtypeProperty.IsUserEditable = userProfilePropertyInfo.IsUserEditable; if (userProfilePropertyInfo.DefaultPrivacy.HasValue) { profileSubtypeProperty.DefaultPrivacy = userProfilePropertyInfo.DefaultPrivacy.Value; } } profileSubtypeProperty.Commit(); return(profileSubtypeProperty); }
static void MaritalStatus() { //Code example adds a new property called Marital Status. using (SPSite site = new SPSite("http://servername")) { //SPServiceContext context = SPServiceContext.GetContext(site); //ClientContext context = new ClientContext(site); //ServerContext context = ServerContext.GetContext(site); UserProfileConfigManager upcm = new UserProfileConfigManager(); try { ProfilePropertyManager ppm = upcm.ProfilePropertyManager; // create core property CorePropertyManager cpm = ppm.GetCoreProperties(); CoreProperty cp = cpm.Create(false); cp.Name = "MaritalStatus"; cp.DisplayName = "Marital Status"; cp.Type = PropertyDataType.StringSingleValue; cp.Length = 100; cpm.Add(cp); // create profile type property ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User); ProfileTypeProperty ptp = ptpm.Create(cp); ptpm.Add(ptp); // create profile subtype property ProfileSubtypeManager psm = ProfileSubtypeManager.Get(); ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User)); ProfileSubtypePropertyManager pspm = ps.Properties; ProfileSubtypeProperty psp = pspm.Create(ptp); psp.PrivacyPolicy = PrivacyPolicy.OptIn; psp.DefaultPrivacy = Privacy.Organization; pspm.Add(psp); } catch (DuplicateEntryException e) { Console.WriteLine(e.Message); Console.Read(); } catch (System.Exception e2) { Console.WriteLine(e2.Message); Console.Read(); } } }
private static ProfileSubtypeProperty EnsureProfileSubtypeProperty( ProfileTypeProperty profileTypeProperty, UserProfilePropertyInfo userProfilePropertyInfo, ProfileSubtypePropertyManager profileSubtypePropertyManager) { var profileSubtypeProperty = profileSubtypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name); if (profileSubtypeProperty == null) { profileSubtypeProperty = profileSubtypePropertyManager.Create(profileTypeProperty); profileSubtypeProperty.IsUserEditable = userProfilePropertyInfo.IsUserEditable; if (userProfilePropertyInfo.DefaultPrivacy.HasValue) { profileSubtypeProperty.DefaultPrivacy = userProfilePropertyInfo.DefaultPrivacy.Value; } profileSubtypePropertyManager.Add(profileSubtypeProperty); } else { profileSubtypeProperty.IsUserEditable = userProfilePropertyInfo.IsUserEditable; if (userProfilePropertyInfo.DefaultPrivacy.HasValue) { profileSubtypeProperty.DefaultPrivacy = userProfilePropertyInfo.DefaultPrivacy.Value; } } profileSubtypeProperty.Commit(); return profileSubtypeProperty; }