protected virtual CoreProperty GetCurrentCoreProperty(SPSite site, CorePropertyDefinition definition) { CoreProperty result = null; var serverContext = SPServiceContext.GetContext(site); var profileManager = new UserProfileManager(serverContext); var profilePropertiesManager = new UserProfileConfigManager(serverContext).ProfilePropertyManager; var corePropertiesManager = profilePropertiesManager.GetCoreProperties(); // would return NULL, no try-catch is required result = corePropertiesManager.GetPropertyByName(definition.Name); return(result); }
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 virtual CoreProperty CreateNewCoreProperty(SPSite site, CorePropertyDefinition definition) { var serverContext = SPServiceContext.GetContext(site); var profileManager = new UserProfileManager(serverContext); var profilePropertiesManager = new UserProfileConfigManager(serverContext).ProfilePropertyManager; var corePropertiesManager = profilePropertiesManager.GetCoreProperties(); var coreProp = corePropertiesManager.Create(false); coreProp.Name = definition.Name; coreProp.DisplayName = definition.DisplayName; coreProp.Type = definition.Type; if (!string.IsNullOrEmpty(definition.Description)) { coreProp.Description = definition.Description; } if (definition.Length.HasValue) { coreProp.Length = definition.Length.Value; } if (definition.IsAlias.HasValue) { coreProp.IsAlias = definition.IsAlias.Value; } if (definition.IsSearchable.HasValue) { coreProp.IsSearchable = definition.IsSearchable.Value; } if (definition.IsMultivalued.HasValue) { coreProp.IsMultivalued = definition.IsMultivalued.Value; } corePropertiesManager.Add(coreProp); return(coreProp); }
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; } }