static void AddProfileProperty(string name, string displayName, bool isMultidValue) { using (SPSite oSite = new SPSite("http://servername")) { //SPServiceContext oServContext = SPServiceContext.GetContext(oSite); ClientContext clientContext = new ClientContext("http://svg-ronald:8080/"); ProfilePropertyManager prfPropMgr; ProfileSubtypeManager prfTypeMgr; ProfileSubtypePropertyManager prftypePropMgr; ProfileTypePropertyManager typPropMgr; ProfileSubtypeProperty prfTypeProp; ProfileTypeProperty prfProp; ProfileSubtype prfType; CorePropertyManager corePropMgr; CoreProperty coreProp; //prfPropMgr = new UserProfileConfigManager(oServContext).ProfilePropertyManager; prfPropMgr = new UserProfileConfigManager().ProfilePropertyManager; //prfProp.Name = name; corePropMgr = prfPropMgr.GetCoreProperties(); coreProp = corePropMgr.Create(false); coreProp.Name = name; coreProp.DisplayName = displayName; coreProp.IsMultivalued = isMultidValue; coreProp.Type = PropertyDataType.StringMultiValue; coreProp.Length = 1024; corePropMgr.Add(coreProp); typPropMgr = prfPropMgr.GetProfileTypeProperties(ProfileType.User); prfProp = typPropMgr.Create(coreProp); prfProp.IsVisibleOnViewer = true; typPropMgr.Add(prfProp); //prftypePropMgr.Add(prfTypeProp); prftypePropMgr = prfPropMgr.GetProfileSubtypeProperties(name); prfTypeProp = prftypePropMgr.Create(prfProp); prfTypeProp.IsUserEditable = true; prfTypeProp.DefaultPrivacy = Privacy.Public; prfTypeProp.UserOverridePrivacy = true; } }
public void CreateUIDProperty() { var propManager = _propertyManager.GetCoreProperties(); var property = propManager.GetPropertyByName(UUID_PROPERTY); if (property != null) { return; } Logger.WriteInfo("Creating property '" + UUID_PROPERTY + "' in profile service"); var profilePropMgr = new UserProfileConfigManager(_context).ProfilePropertyManager; var corePropManager = profilePropMgr.GetCoreProperties(); // Create the property. var coreProp = corePropManager.Create(false); coreProp.Name = UUID_PROPERTY; coreProp.DisplayName = "SPC UID"; coreProp.Type = PropertyDataType.String; coreProp.Length = 36; coreProp.IsMultivalued = false; coreProp.IsSearchable = true; corePropManager.Add(coreProp); // Create a profile type property and make the core property visible in the Details section page. var typePropManager = profilePropMgr.GetProfileTypeProperties(ProfileType.User); var typeProp = typePropManager.Create(coreProp); typeProp.IsVisibleOnViewer = true; typePropManager.Add(typeProp); // Create a profile subtype property. var subtypeManager = ProfileSubtypeManager.Get(_context); var subtype = subtypeManager.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User)); var subtypePropMgr = profilePropMgr.GetProfileSubtypeProperties(subtype.Name); var subtypeProp = subtypePropMgr.Create(typeProp); subtypeProp.IsUserEditable = false; subtypeProp.DefaultPrivacy = Privacy.Public; subtypeProp.UserOverridePrivacy = true; subtypePropMgr.Add(subtypeProp); Logger.WriteInfo("Created SPC UID property in profile service"); }
protected override void Fill() { try { if (SPA.User.Count() == 0) { UserProfileManager userProfileManager = new UserProfileManager(SPServiceContext.GetContext(SPContext.Current.Site)); ProfilePropertyManager profilePropMgr = new UserProfileConfigManager(SPServiceContext.GetContext(SPContext.Current.Site)).ProfilePropertyManager; ProfileSubtypePropertyManager subtypePropMgr = profilePropMgr.GetProfileSubtypeProperties("UserProfile"); UserProfile userProfile = userProfileManager.GetUserProfile(Context.User.Identity.Name.Replace("i:0#.w|", "").Replace("0#.w|", "")); hfUserProfileRecordID.Value = (userProfile.RecordId.ToString()); IEnumerator<ProfileSubtypeProperty> userProfileSubtypeProperties = subtypePropMgr.GetEnumerator(); while (userProfileSubtypeProperties.MoveNext()) { string propName = userProfileSubtypeProperties.Current.Name; ProfileValueCollectionBase values = userProfile.GetProfileValueCollection(propName); if (values.Count > 0) { // Handle multivalue properties. foreach (var value in values) { switch (propName) { case "AccountName": lblAccountNameView.Text = value.ToString(); break; case "FirstName": lblFirstNameView.Text = value.ToString(); break; case "LastName": lblLastNameView.Text = value.ToString(); break; case "PreferredName": lblPreferredNameView.Text = value.ToString(); break; case "UserProfile_GUID": lblUserProfileGuidView.Text = value.ToString(); break; case "SPS-UserPrincipalName": lblUserPrincipalNameView.Text = value.ToString(); break; case "SPS-DistinguishedName": lblDistinguishedNameView.Text = value.ToString(); break; } if (ShowDebug) lblErrorMessage.Text += string.Format("Name: {0} Value: {1}</br>", propName, value.ToString()); } } } } else { trAccountName.Visible = false; trLastName.Visible = false; trFirstName.Visible = false; trPreferredName.Visible = false; trUserProfile_GUID.Visible = false; trUserPrincipalName.Visible = false; trDistinguishedName.Visible = false; lblMessageView.CssClass = "ms-error"; lblMessageView.Text = "There are already users in the data system. This option is only available when no user records exist."; btnSave.Visible = false; } } catch (Exception ex) { SPA.Error.WriteError(ex); lblErrorMessage.Text += string.Format("ERROR: {0}", ex.ToString()); } }
protected override void Page_Load(object sender, EventArgs e) { try { base.Page_Load(sender, e); SetupContribute(); ReadParameters(); btnSave.OnClientClick = jsActionSave; jsActionCancel = string.Format("rbnCancelClick('{0}/{1}?filter={2}'); return false;", SPContext.Current.Web.Url, Pages.Users.PAGE_URL, Filter); btnCancel.OnClientClick = jsActionCancel; ibtnRibbonCancel.OnClientClick = jsActionCancel; lbtnRibbonCancel.OnClientClick = jsActionCancel; if (spePickUser.ResolvedEntities.Count > 0) { foreach (PickerEntity entity in spePickUser.ResolvedEntities) { lblUserNameView.Text = entity.Claim.Value; UserProfileManager userProfileManager = new UserProfileManager(SPServiceContext.GetContext(SPContext.Current.Site)); ProfilePropertyManager profilePropMgr = new UserProfileConfigManager(SPServiceContext.GetContext(SPContext.Current.Site)).ProfilePropertyManager; ProfileSubtypePropertyManager subtypePropMgr = profilePropMgr.GetProfileSubtypeProperties("UserProfile"); UserProfile userProfile = userProfileManager.GetUserProfile(entity.Claim.Value); hfUserProfileRecordID.Value = (userProfile.RecordId.ToString()); try { IEnumerator <ProfileSubtypeProperty> userProfileSubtypeProperties = subtypePropMgr.GetEnumerator(); while (userProfileSubtypeProperties.MoveNext()) { string propName = userProfileSubtypeProperties.Current.Name; ProfileValueCollectionBase values = userProfile.GetProfileValueCollection(propName); if (values.Count > 0) { // Handle multivalue properties. foreach (var value in values) { switch (propName) { case "FirstName": txtFirstName.Text = value.ToString(); break; case "LastName": txtLastName.Text = value.ToString(); break; case "PreferredName": txtPreferredName.Text = value.ToString(); break; case "UserProfile_GUID": lblSPObjectGuidView.Text = value.ToString(); break; //case "SPS-UserPrincipalName": // lblUserPrincipalNameView.Text = value.ToString(); // break; //case "SPS-DistinguishedName": // lblDistinguishedNameView.Text = value.ToString(); // break; } if (ShowDebug) { lblErrorMessage.Text += string.Format("Name: {0} Value: {1}</br>", propName, value.ToString()); } } } } } catch { txtLastName.Text = "Profile Not Found"; txtFirstName.Text = "Profile Not Found"; } } } if (!IsPostBack) { ibtnRibbonDelete.OnClientClick = "return confirm('Are you sure you want to delete this item?');"; lbtnRibbonDelete.OnClientClick = "return confirm('Are you sure you want to delete this item?');"; Fill(); } else { HandlePostBack(); } } catch (Exception ex) { SPA.Error.WriteError(ex); if (ShowDebug) { lblErrorMessage.Text = ex.ToString(); } } }